Menu
Topics Index
...
`

String Methods


If you need explanation Read this topic

If you need Answer Take test on this topic

String Methods
What will be the output of the program?
public class Statement {
    public static void main(String[] String) {
        if ("String ".trim() == "String") {
            System.out.print("true1 ");
        }
        if (" String ".trim() == "String") {
            System.out.print("true2 ");
        }
        if ("String".trim() == "String") {
            System.out.print("true3 ");
        }
        if ("Str ing ".trim() == "String") {
            System.out.print("true4");
        }
    }
}

A. true1 true2 true3 true4
B. true1 true2 true4
C. true1 true2
D. true1
E. true3
F. Compilation Error or Runtime Error
Topic: Java String trim() Method - trim() Method 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.

A is the ans. as evry stmnt  is satisfied .

Posted by Shabaaz Shaikz    2014-09-09 12:43:17


E....

Posted by Rajat Panjwani    2014-09-09 12:52:07


d.only third stmnt turns out to be true....rest if cndtn r false

Posted by Nasir Khan    2014-09-09 12:55:38


ans is A  astrim() removes all spaces

Posted by Ramya Reddy Addulla    2014-09-09 13:00:13


U r absolutely right Rajat Panjwani..ans is E..

Posted by Abhishek Kumar    2014-09-09 13:05:44


A

Posted by Raju VarshnEy    2014-09-09 13:43:40


E. == returns true when both the string under comparison are referring to the same object. Here "equals" may be used than "==" to get better result of trim(). true3 gets printed as both the strings are same as there are no spaces to be removed by trim()

Posted by Ankur Verma    2014-09-09 20:36:41


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

Posted by Merit Campus    2014-09-10 04:19:49


© meritcampus 2019

All Rights Reserved.

Open In App