Since String.split()
works with regular expressions, this snippet:
String s = \"str?str?argh\";
s.split(\"r?\");
... yields: <
This works perfect as well:
public static List<String> splitNonRegex(String input, String delim)
{
List<String> l = new ArrayList<String>();
int offset = 0;
while (true)
{
int index = input.indexOf(delim, offset);
if (index == -1)
{
l.add(input.substring(offset));
return l;
} else
{
l.add(input.substring(offset, index));
offset = (index + delim.length());
}
}
}
String[] strs = str.split(Pattern.quote("r?"));