Easy keyboard input (JDK1.5)

A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods.
import java.util.*;

class TestScanner {
  public static void main(String args[]) {
    String input = "10:11:12";
    Scanner sc = new Scanner(input).useDelimiter(":");
    while (sc.hasNextInt()) {
          int i = sc.nextInt();
          System.out.println(i);
    }
  }
}



If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2010
[ home ]