Breaking a String into Words - Java Language Basics

Java examples for Language Basics:String

Description

Breaking a String into Words

Demo Code

import java.util.StringTokenizer;

public class Main {
  public static void main(String[] argv) {
    String aString = "word1 word2 word3";
    StringTokenizer parser = new StringTokenizer(aString);
    while (parser.hasMoreTokens()) {
      System.out.println(parser.nextToken());
    }/*  w  w  w .  j a  va  2s .c  o m*/

  }
}

Result


Related Tutorials