Java String split by space

Description

Java String split by space

public class Main {
  // execute application
  public static void main(String[] args) {
    String sentence = "this is a test";

    // process user sentence
    String[] tokens = sentence.split(" ");
    System.out.printf("Number of elements: %d\nThe tokens are:\n", tokens.length);

    for (String token : tokens)
      System.out.println(token);/*from w w  w. j av a 2  s  .  c om*/
  }
}



PreviousNext

Related