READ Free Dumps For Oracle- 1z0-804
Question ID 21455 | Given:
public class StringSplit01 {
public static void main(String[] args) {
String names = "John-.-George-.-Paul-.-Ringo";
String[] results = names.split("-..");
for(String str:results) {
System.out.println(str);
}
}
}
What is the result?
|
Option A | John-.-George-.-Paul-.-Ringo
|
Option B | John
George
Paul
Ringo
|
Option C | John -
George -
Paul -
Ringo -
|
Option D | An exception is thrown at runtime
|
Option E | Compilation fails
|
Correct Answer | B |
Explanation Explanation: The split() method is used to split a string into an array of substrings, and returns the new array. regex: - followed by two characters
Question ID 21456 | Given:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Test {
private static String REGEX = "\\Sto\\S|\\bo\\b";
private static String INPUT = "Nice to see you,to,be fine.";
private static String REPLACE = ",";
public static void main(String[] args) {
Pattern p = Pattern.compile(REGEX);
Matcher m = p.matcher(INPUT);
INPUT = m.replaceAll(REPLACE);
System.out.println(INPUT);
}
}
What is the result?
|
Option A | Nice to see you,be fine
|
Option B | Nice,see you,be fine
|
Option C | Nice,see you, to, be fine
|
Option D | Nice, see you, be fine
|
Option E | Nice to see y, u, be fine
|
Correct Answer | A |
Explanation Explanation: The text ",to," is replaced by the ","