Java tutorial
//package com.java2s; public class Main { public static Object decode(Object expr, Object... pat) { for (int i = 0; i < pat.length; i++) { if (i + 1 >= pat.length) //default return pat[i]; if (expr.equals(pat[i++])) return pat[i]; } return null; } }