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
Join The Discussion
Comments ( 4 )
Related Questions on Strings
In Java, which class is used to represent a sequence of characters as a string?
A. String
B. StringBuilder
C. StringSequence
D. StringArray
What is the correct way to create a new empty String object in Java?
A. String emptyString = "";
B. String emptyString = new String();
C. String emptyString = " ";
D. String emptyString = null;
E. Both A and B
Which of the following methods is used to compare two strings for equality in Java?
A. equals()
B. compareTo()
C. equalsIgnoreCase()
D. compare()
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