I have a bunch of characters and want to remove everything that isn\'t a \'#\' \'.\' \'E\' and \'G\'.
I tried to use this:
if (buffer.get(buffertest) ==
This root problem is incorrect use of the bitwise OR operator, and the Java operator precedence hierarchy. Java expressions of this type are evaluated left to right, and the == operator takes precedence over |. Which when combined, your expression roughly translates to:
(buffer.get(buffertest) == 'G') | 'E' | '#' | '.'
The first part of the expression buffer.get(buffertest) == 'G' evaluates to a boolean.'E' | '#' | '.'` evaluates to an int, which is narrowed to a char
The second part of the expression
Which leads to an incompatible type compile time error. You can correct your code by expanding the check this way:
char ch = buffer.get(buffertest);
if(ch == 'G' || ch == 'E' || ch == '#' || ch == '.') {
// do something
}