0
Trim( )
which one gives output as true?If("string”.trim()==“string”) If(" string”.trim()==“string”) If("string ”.trim()==“string”)
10 Answers
+ 2
I have told you that there are syntax errors in code. I just copy & paste it in Playground and I got error message. If you noticed what I said and fix the problem, you can also easily find the true answer in Playground.
Hint: Use of `equals` yields true for all three expressions. So there bro Indian ...
+ 2
Your code have syntax errors.
1. The quotes for the string is not regular double quote character.
2. Your `if` statement uses uppercase letter 'i'.
3. You should use `equals` method to check for string equality rather than == or != operator.
+ 2
Ok ok
Good job bro Indian 👍
+ 1
okay Ipang
0
1.here word is “string”
2. jus to ask dbt i put that that ‘if’
3. i can use == bcz it compares obj references... in simple it compares string based on reference... if 2 string referes same obj output will b true nly
and equals() i know ,ofcourse it compares string Data Ipang
0
You already know about == and `equals`. So your post here is a sort of way to test others. Is that it bro Indian ?
0
u did nt said which one gets true bro?? it is with concept trim( ) so the thing i want is which is true Ipang
0
Ipang
public class Program
{
public static void main(String[] args) {
String s="string";
String s1=" string";
String s2=" string".trim();
String s3="string ";
String s4="string ".trim();
String s5="string";
//1.if
if (s==s5)
{
System.out.print("'string'=='string' ");
System.out.println(s==s5);
}
//2.if
if(s==s5.trim())
{
System.out.print("'string'=='string.trim()' ");
System.out.println(s==s5.trim());
}
//3.if
if (s==s1.trim())
{
System.out.println("true");
}
else {System.out.print("'string'==' string.trim()' ");
System.out.println(s==s1.trim());
}
//4.if
if(s==s2)
{
System.out.println("true");
}
else {
System.out.print("s==s2 is ");
System.out.println(s==s2);
}
//5.if
if(s==s4)
{
System.out.println("true");
}
else{ System.out.print("s==s4 is ");
System.out.println(s==s4);
}
}
}
0
What happened bro Indian ?
0
it got it😊Ipang