I have recently started learning Java. I got stuck on Splitting the particular string. Here is the string:
String head = "(*, grandparent(X,Y))";
I want to split the string such that it will give two tokens. The two tokens should be * and grandparent(X,Y). I have tried to split it by
StringTokenizer st=new StringTokenizer(head,",");
System.out.println("The tokens are: " + st.countTokens());
But I am getting three tokens if I split it by comma.
I don't want to split it by regex. Could you guys please help me?
StringTokenizer. As the javadoc has been saying since Java 1.4:StringTokenizeris a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use thesplitmethod ofStringor the java.util.regex package instead.,, no?