I have a following code to split my input String:
import org.apache.commons.lang.StringUtils;
public class SplitTest {
public static void main(String args[]) {
String input = "A||B||||D||E";
String result[] = StringUtils.split(input, "||");
for (int i = 0; i < result.length; i++) {
System.out.println("result[" + i + "]:" + result[i]);
}
}
}
And I was expecting output as:
Expected Output:
result[0]:A
result[1]:B
result[2]:
result[3]:D
result[4]:E
Real Output:
result[0]:A
result[1]:B
result[2]:D
result[3]:E
Can anyone tell me why this is happening? What Can I do to achieve my expected output?