If you use something like this, it will work:
if (raw.charAt(3) == '-' && raw.charAt(7) == '-') { System.out.println("2 Hyphens at 3 and 7"); } else if (raw.charAt(3) == '-' && raw.charAt(8) == '-') { System.out.println("2 Hyphens at 3 and 8"); } else if (raw.charAt(3) == '-' && raw.charAt(9) == '-') { System.out.println("2 Hyphens at 3 and 9"); }
The problem is that raw.charAt(n) returns a char , not a String . The equals() method can be used only for objects. Char is a primitive data type that has no methods. In characters you must use operators such as == or != .
source share