Example of what I want to do:
If you pass in \"abc|xyz\"
as the first argument and \"|\"
as the second argument the method returns List(\"abc
Try using the split
method:
return Arrays.asList(string.split("\\|"));
The two backslashes are there because split
accepts a regex, and |
is a special character in regexes. Also, backslash is a special character in Java strings. So the first backslash escapes the second one, which escapes the |
.
Arrays.asList
will convert the array returned by split
to a list.
Is it what you are looking for ??There is a predefined function in String class.Make use of it
String original ="abc|xyz";
String[] resulted =original.split("\\|");//returns a String array
Play with the resulted
array here.
Good luck.
If you want to do this using characters...