2

In my application I need to convert dot separated string to arraylist. I have seen in many places split function of string is used to separate comma separated string to Array List.I studied in the documentation split function requires expression for splitting.In my case I provided dot and it is not converting.Am I missing something? Please help me.Below is my code I am using

Here,

 groupHierarchy.levelPrefix = 4201.4202;
 ArrayList<String> levelPrefixList = new ArrayList<>(
                Arrays.asList(groupHierarchy.levelPrefix.split(".")));

When I log this it shows

Log.e("tracking","level prefix list is "+ levelPrefixList);
ItamarG3
  • 4,092
  • 6
  • 31
  • 44
Abdul Waheed
  • 4,540
  • 6
  • 35
  • 58
  • as split method expects a regular expression so you must use \\ ( double slash) to say you need to match .(dot) – SSH Oct 05 '15 at 06:42

1 Answers1

3

Use following:

groupHierarchy.levelPrefix.split("\\.")

public String[] split(String regex) use regex, so you have to escape "."

See Split String on . as delimiter for more details.

Community
  • 1
  • 1
Sumit Singh
  • 15,743
  • 6
  • 59
  • 89