String s=" hello "; s+=" word "; s.trim(); System.out.println(s); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

String s=" hello "; s+=" word "; s.trim(); System.out.println(s);

why trim() not work here

1st Sep 2017, 4:00 PM
narendra kumar
narendra kumar - avatar
3 Answers
+ 3
trim() returns a String. It is not a void method since Strings are immutable. So, you need to assign s to the value of trim(). Like this: s = s.trim();
1st Sep 2017, 4:15 PM
Rrestoring faith
Rrestoring faith - avatar
0
put them in String builder or buffer and then trim
1st Sep 2017, 4:06 PM
corejava
0
what word u gonna trim here u didn't mention
1st Sep 2017, 4:08 PM
corejava