title: How to ignore white spaces in Java
body: <p>I was wondering how to ignore spaces in Java. This program allows you to enter your first, middle and surname which then outputs your initials. I'm now trying to make it ignore any white spaces. Thanks in advance!</p>
  
  <pre><code>    String fullName;
      char firstName;
      char secondName;
      char surname;
      int space1;
      int space2;
  
      System.out.println("Please enter your first name, your second name and your surname: ");
      fullName = kybd.nextLine();
  
      firstName = fullName.charAt(0);
      space1 = fullName.indexOf(" ");
      secondName = fullName.charAt(space1 + 1);
      space2 = fullName.lastIndexOf(" ");
      surname = fullName.charAt(space2 + 1);
  
      System.out.println("Initials: " + firstName + secondName + surname);
  }
  </code></pre>
  
  <p>}</p>