Possible Duplicate:
Java StringTokenizer, empty null tokens
Considering this java snippet:
public class Test {
public static void main(String[] args) {
String s1 = "1;2;3;4;5";
String s2 = "1;2;;;";
String[] splits1 = s1.split(";");
String[] splits2 = s2.split(";");
System.out.println(splits1.length);
System.out.println(splits2.length);
}
}
OUTPUT:
5
2
I need some alternatives to extracting arrays with same lengths.
If there are four semicolons (";") in the searched string (ex s2) then I would like to have length=5 of splited array (splits2) with null elements where appropriate (splits2[2]=null, splits2[3]=null etc).
Can you please provide solutions?