Java String split String by space/whitespace

Description

Java String split String by space/whitespace

public class Main {
  public static void main(String[] args) {
    String sampleString = "CSS Java Javascript";
    String[] langs = sampleString.split(" ");
    for (String lang : langs) {
      System.out.println(">" + lang + "<");
    }//from   ww w.  j av a  2s.c  om
    
    sampleString = "CSS  HTML    Java     Javascript";
    langs = sampleString.split("\\s");

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



PreviousNext

Related