Examveda
Examveda

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); 
	} 
}

A. abc

B. 123

C. Runtime exception thrown

D. Compilation error

Answer: Option A


This Question Belongs to Java Program >> Strings

Join The Discussion

Comments ( 4 )

  1. Saraswathi Chakarawarthy
    Saraswathi Chakarawarthy :
    4 years ago

    answer:abc

  2. Abisha Benjamin
    Abisha Benjamin :
    5 years ago

    Because it is a string array so it only holds the string values.

  3. Madhu Velpuri
    Madhu Velpuri :
    7 years ago

    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}

  4. Manasa D
    Manasa D :
    7 years ago

    How

Related Questions on Strings