I have a text file which contains lot of permutations and combinations of special characters, white space and data. I am storing the content of this file into an array list,
You could do this:
String str = "...";
List<String> List = Arrays.asList(str.split(","));
Basically the .split() method will split the string according to (in this case) delimiter you are passing and will return an array of strings.
However, you seem to be after a List of Strings rather than an array, so the array must be turned into a list by using the Arrays.asList() utility. Just as an FYI you could also do something like so:
String str = "...";
ArrayList<String> List = Arrays.asList(str.split(","));
The default delimiter for Scanner is defined as the pattern \p{javaWhitespace}+
, so if you want to also treat comma and dot as a delimiter, try
input.useDelimiter("(\\p{javaWhitespace}|\\.|,)+");
Note you need to escape dot, as that is a special character in regular expressions.
Use escaped character like this:
input.useDelimiter("\\.");