Given a string in the form of:
String myStr = "5.1\t3.5\t1.4\t0.2\t0.0";
If I call:
StringTokenizer token = new StringTokenizer(myStr, "\\s+");
String firstElement = token.nextToken();
firstElement then equals the whole string. In contrast, if I call:
StringTokenizer token2 = new StringTokenizer(myStr);
String firstElement = token2.nextToken();
firstElement equals "5.1". Similarly if I use String split as below:
String[] splitArray = myStr.split("\\s+")
String firstElement = splitArray[0];
then, firstElement is "5.1".
I understand StringTokenizer is discouraged for use and is a classified as a "legacy class". My intent here is to understand why the same delimiter works differently between split and StringTokenizer. I would have expected the first example to work like the latter two, but for some reason, it is skipping the tabs. Any guidance on what I am missing would be much appreciated.
Note I am running 1.7.0_19 on OSX in Eclipse, but I would not expect those variables to have an effect here.