Problem
My code is currently using a String[] array, however I am finding I need to write a foreach loop to check if it contains certain characters (I am only working with 18 nums/ops, 1...10, 25, 50, 75 100, +, -, *, /)
String[] copy = {"100", "10", "25", "9", "8", "-", "75", "-", "-", "-", "-"};
int opCheck = 0;
for (String token : copy) {
if (token.equals("-") || token.equals("/")) {
opCheck++;
}
}
if (opCheck != 5) {
postfixArray[postfixIndex++] = copy;
}
I understand String[] operations aren't the fastest, and am wondering what other ways are faster.
Possible Solutions
I have thought about possibly encoding the content, i.e.
1 = a, 2 = b....10 = j, + = o, - = p
1 = 1, 2 = 2....10 = 10, + = 11, - = 12
What would be faster to check if it contains certain characters?
String[] strArr = {"100", "10", "25", "9", "8", "-", "75", "-", "-", "-", "-"};
int[] intArr = {100, 10, 25, 9, 8, 12, 75, 12, 12, 12, 12} // FYI - = 12
char[] chArr = {'n', 'j', 'k', 'i', 'h', 'p', 'm', 'p', 'p', 'p', 'p'}
String str = "njkihpmpppp"