Knowee
Questions
Features
Study Tools

String abc = " a b c ";System.out.println("!" + abc.trim() + "!"); //is this output trimmed?

Question

String abc = " a b c ";System.out.println("!" + abc.trim() + "!"); //is this output trimmed?

🧐 Not the exact question you are looking for?Go ask a question

Solution

Yes, the output is trimmed. The trim() method in Java removes leading and trailing spaces of a string. So, the string " a b c " becomes "a b c". The output of your code will be "!a b c!". The exclamation marks are not part of the trim method, they are just there to clearly show the beginning and end of the string after trimming.

Similar Questions

String myString = new String("This is a string!");System.out.println(myString.toString());What will be returned by this snippet of code?

What is the output of the following code snippet? String str1 = "Java"; String str2 = new String("Java"); System.out.println(str1 == str2);

What will be the output of the program?String x = "xyz";x.toUpperCase(); /* Line 2 */String y = x.replace('Y', 'y');y = y + "abc";System.out.println(y);abcXyZabcxyzxyzabcXyZabc

What will be the output of the program?String s = "ABC"; s.toLowerCase(); s += "def"; System.out.println(s);ABCabcABCdefCompile Error

String myString = new String("This is a string!");System.out.println(myString instanceof Object);What is the output that you get when you execute this snippet of code?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.