Lookup Table Code
- Here's something I whipped up and checked in about 20 minutes.
- I spent most of the time actually getting the hello world version
working.
public class lookup{
private static char[] charStore;
private static boolean []lookupTable ;
static private void initLookupTable() {
for (int i = 0; i < 256; i++) {
lookupTable[i]=false;
}
}
static private void initCharStore(String initString) {
for (int i = 0; i < initString.length(); i++) {
char addChar=initString.charAt(i);
int offset = (int) addChar;
lookupTable[offset]=true;
}
}
static private boolean isPresent(char searchChar) {
int offset = (int) searchChar;
return(lookupTable[offset]);
}
/**Main method*/
public static void main(String[] args) {
charStore = new char[10];
lookupTable = new boolean[256];
initLookupTable();
initCharStore("birds");
System.out.println(isPresent('b'));
System.out.println(isPresent('z'));
System.out.println(isPresent('r'));
System.out.println(isPresent('b'));
}
}
- Note the explicit conversion of char.