Accenture Accenture Primer Practice Question
Predict the output import java.util.regex.*; public class Hello {Answer options
A
public static void main(String args[])
B
String s="REGULAREXPRESSION";
C
String r="";
D
s=s.replaceAll(r,",");
E
System.out.println(s);
F
(a.) ,R,E,G,U,L,A,R,E,X,P,R,E,S,S,I,O,N,
G
(b.) REGULAREXPRESSION
H
(c.) None
I
(d.) All
Correct answer: (a.) ,R,E,G,U,L,A,R,E,X,P,R,E,S,S,I,O,N,
Explanation
replaceAll("", ",") uses an empty-string regex which matches every position between characters (and at start/end). Result: ',R,E,G,U,L,A,R,E,X,P,R,E,S,S,I,O,N,'.