All pastes #230694 Raw Edit

Miscellany

public text v1 · immutable
#230694 ·published 2006-10-31 11:47 UTC
rendered paste body
import java.util.regex.Pattern;
import java.util.regex.Matcher;

/**
 * @author Andreas Prudzilko
 */
public class Test {

	public static void main(String[] args) {
		String[] myarr = new String[]{
				"a", "b", "c", "d", "e", "f", "g", "h", "j"
		};

		int length = -1;
		try {
			String foo;
			for (int i = 0; i < Integer.MAX_VALUE ; foo = myarr[i++]);
		} catch (IndexOutOfBoundsException e) {
			Pattern p = Pattern.compile("\\d+");
			String message = e.getMessage();
			Matcher m = p.matcher(message);
			if (m.matches()) length = Integer.parseInt(m.group(0));
		}
		System.out.println("length: "+length);
	}

}