Thomas ClassiFied Thomas ClassiFied - 1 month ago 21
Java Question

Trim and Lowercase

Every time I try doing the trim method and the lowercase method it doesn't show the way I want it.

sentence.trim();
sentence.toLowerCase();
System.out.println("\"" + sentence + "\"" + " ---> ");


For example, if I input " Hello World! ", it will print out " Hello World! " and not use any of the methods.

Answer

They don't trim or lowercase "in-place"

You could just put it in the print statement, though

System.out.println("\"" + sentence.trim().toLowerCase() + "\"" + " ---> ");