What will be the output?
public class Test{
public static void main (String[] args){
String test = "a1b2c3";
String[] tokens = test.split("\\d");
for(String s: tokens)
System.out.print(s);
}
}
public class Test{
public static void main (String[] args){
String test = "a1b2c3";
String[] tokens = test.split("\\d");
for(String s: tokens)
System.out.print(s);
}
}
A. abc
B. 123
C. Runtime exception thrown
D. Compilation error
Answer: Option A
answer:abc
Because it is a string array so it only holds the string values.
split method available in String class uses Regular Expressions to split the strings.
//d refers to split the string based on digits
String tokens[] = s.split("//d") gives the array as {a,b,c}
How