FileDocCategorySizeDatePackage
StringParse.javaAPI DocExample876Sat Apr 28 10:22:44 BST 2001None

StringParse

public class StringParse extends Object
Show use of MutableInteger to "pass back" a value in addition to a function's return value.

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

		MutableInteger mi = new MutableInteger();
		String text = "Hello, World";
		char c = 'W";
		if (parse(text, c, mi)) {
			System.out.println("Character " + c + " found at offset " + mi + " in " + text);
		} else {
			System.out.println("Not found");
		}
	
public static booleanparse(java.lang.String in, char lookFor, MutableInteger whereFound)
This is the function that has a return value of true but also "passes back" the offset into the String where a value was found. Contrived example!

		int i = in.indexOf(lookFor);
		if (i == -1)
			return false;	// not found
		whereFound.setValue(i);	// say where found
		return true;		// say that it was found