I have a String. This line has comma separated values (e.g. Bob, John, Jill), but sometimes this line has only one value (e.g. Bob). I need to extract these values, so I'm using something like this:
String str = "Bob,John,Jill";
StringTokenizer strTok = new StringTokenizer(str , ",");
This works, and now I have access to 3 names separately., But what if my line contains only the word Bob (now there is no comma). This code fails, so my solution is to check for a comma, and if that happens, I tocanize, if not, then I just get the line (I know this condition is not good because it does not handle null and other conditions properly, but I just want this not to show the problem):
if( (str != null) && (!str.isEmpty()) && (!str.contains(",")) && (str.length() > 0)){
}
else{
}
, , , ? , , - , ?