In this class I'm splitting variables on different delimiters(namely || and &&)
Here is my class:
public class Test {
public static void main(String[] args) {
String orStatement = "here||there";
String andStatement = "here&&there";
splitOr(orStatement);
splitAnd(andStatement);
}
public static String[] splitOr(String stringvar){
if(!stringvar.contains("||")){
throw new IllegalArgumentException("Must contain a double pipe || to split into or statements");
}
String[] orArray = stringvar.split("||");
for(int i=0;i<orArray.length;i++){
System.out.println(orArray[i]);
}
return orArray;
}
public static String[] splitAnd(String stringvar){
if(!stringvar.contains("&&")){
throw new IllegalArgumentException("Must contain a double ampersand && to split into and statements");
}
String[] andArray = stringvar.split("&&");
for(int i=0;i<andArray.length;i++){
System.out.println(andArray[i]);
}
return andArray;
}
}
And here is the result:
h
e
r
e
|
|
t
h
e
r
e
here
there
Why am I getting this weird ambitious splitting?