sscanf equivalent in Java

Dariusz G. Jagielski picture Dariusz G. Jagielski · May 10, 2012 · Viewed 8.9k times · Source

Possible Duplicate:
what is the Java equivalent of sscanf for parsing values from a string using a known pattern?

I'm pretty new to Java, but seeing how useful the sscanf function is, I wonder if there is an equivalent in Java. I've got many pretty much formatted strings (namely, writing scripting language for my purposes), so regular expressions are overkill here.

Answer

user unknown picture user unknown · May 10, 2012
Scanner scanner = new Scanner ("2 A text 3 4");
scanner.nextInt (); // 2
scanner.next ();    // A 
scanner.next ();    // text
scanner.nextInt (); // 3
scanner.nextInt (); // 4
// and so on.

Here is the official documentation of the Scanner class.