// linear search int[] theSet = { 32, 64, 128, 256 }; boolean found = false; for ( int candidate: theSet ) { if ( index == candidate ) { found = true; break; } } if ( found ) { out.println( index + " was in the set" ); }