Menu
Topics Index
...
`

Strings replacement1216


If you need explanation Read this topic

If you need Answer Take test on this topic

Strings replacement1216
What will be the output of the following program?
public class Replace {

    public static void main(String a[]) {
        String replaceStr = "<B>Good Day<\\B>";
        System.out.println("Before replace: " + replaceStr);
        replaceStr = replaceStr.replaceAll("\\<.*?\\>", "");
        System.out.println("After replace: " + replaceStr);
    }
}

A. Before replace: <B>Good Day<\B>
After replace: Good Day
B. Before replace: <B>Good Day<\B>
After replace:
C. Before replace: <B>Good Day<\B>
After replace: <B>Good Day<\B>
D. Before replace: <B>Good Day<\B>
After replace: BGood Day\B
E. Compilation Error or Runtime Error
Topic: Additional String Methods in Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is B.

Posted by Gopinath Manchikanti    2014-06-17 12:52:04


A is ans.as before replace as it gets printed.next we r replacing all other symbols with blank so next SOP is jst GOOD DAY

Posted by Shabaaz Shaikz    2014-06-17 12:56:20


Ans is C...initially the string is printed as<B>Good Day</B> and there is no pattern such as given in the string so nothing will be replaced again after replacement also the same output <B>Good Day</B>

Posted by Badam Swathi    2014-06-17 13:04:08


Congratulations Shabaaz Shaikz. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-18 04:13:46


© meritcampus 2019

All Rights Reserved.

Open In App