I have a String like this: String sample = "a|b||d|e";
and I'm trying to split the string with tokenizer
StringTokenizer tokenizer = new StringTokenizer(sample, "|");
String a = tokenizer.nextToken();
String b = tokenizer.nextToken();
String c = tokenizer.nextToken();
String d = tokenizer.nextToken();
When I use the above code, the String variable c
is assigned to the value d
.
StringTokenizer
doesn't initialize a null
value to String c
.
How can we validate and assign default value like -
if it is null
?