Java String split String by multiple space/whitespace

Description

Java String split String by multiple space/whitespace


public class Main {
   public static void main(String[] args) {
      String sampleString = "CSS  HTML    Java     Javascript";
      String[] langs = sampleString.split("\\s+");

      for (String lang : langs) {
         System.out.println(">" + lang + "<");
      }//  w w w .  j a v  a 2s  . com
      
      sampleString = "CSS    HTML \t Java \n Javascript \r\n SQL";
      
      langs = sampleString.split("\\s+");

      for (String lang : langs) {
         System.out.println(">" + lang + "<");
      }      
   }
}



PreviousNext

Related