Search code examples
javamethodstrimlowercase

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.


Solution

  • You need to store the value returned:

    sentence = sentence.trim().toLowerCase();