FileDocCategorySizeDatePackage
StrTokInts.javaAPI DocExample655Wed Jun 19 12:49:06 BST 2002None

StrTokInts

public class StrTokInts extends Object
Given the problem of "I have a String with a fixed number of Integers in it, how do I extract them?". Here's my best readable solution.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		String in = "1  4   5   6   7  908  1231  23  53a";
		StringTokenizer st = new StringTokenizer(in);
		int iKnowHowMany = 9;
		for (int i=0; i<iKnowHowMany; i++) {
			String next = st.nextToken();
			try {
				int n = Integer.parseInt(next);
				System.out.println(i + " --> " + n);
			} catch (NumberFormatException ex) {
				System.out.println(i + " NOT A NUMBER (" + next + ")");
			}
		}