title: Using a simple scanner, reading a string with spaces, how come .trim() method isn't working?
body: <pre><code>import java.util.Scanner;
  import java.lang.String;
  
  public class Test
  {
      public static void main(String[] args)
      {
          char[] sArray;
  
          Scanner scan = new Scanner(System.in);
  
          System.out.print("Enter a Palindrome : ");
          String s = scan.nextLine();
          s = s.trim();
  
          sArray = new char[s.length()];
  
          for(int i = 0; i &lt; s.length(); i++)
          {
              sArray[i] = s.charAt(i);
              System.out.println(sArray[i]);
          }
      }
  }
  </code></pre>