Just to validate if the caracters are valid can do something like this:
String operation = "((TvF->T)^(T->F))->(~F<->T)";
Set<String> validStrings = new HashSet<String>(
Arrays.asList(new String[]{ "(", "T", "v", "F", "->", "<->", "~", ")", "^", "?" })
);
Set<Character> combinedChars = new HashSet<Character>(
Arrays.asList(new Character[]{ '-', '<' })
);
boolean isValidOp = true;
StringBuilder subString = new StringBuilder();
for (int i = 0; i < operation.length(); i++) {
subString.append(operation.charAt(i));
if (validStrings.contains(subString.toString())) {
subString = new StringBuilder();
} else {
if (!combinedChars.contains(operation.charAt(i))) {
isValidOp = false;
break;
}
}
}
System.out.println(isValidOp);
But for what logical expressions validation will need something else, as mentioned in the comments would have to ensure that for example the parentheses are closed when opened.