0

I am trying to use either tokenizer or split in Java for Android, here is my code so far:

ArrayList<String> textList = new ArrayList<String>();
ArrayList<String> alphabet = new ArrayList<String>();
ArrayList<String> numbers = new ArrayList<String>();

textList.add("abc|123");
textList.add("def|456");

But, how to do: add abc, def -> ArrayList alphabet and add 123, 456 -> ArrayList numbers ?

perror
  • 7,071
  • 16
  • 58
  • 85
HS. Choi
  • 13
  • 6
  • possible duplicate of [How to split a string in Java](http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – nkorth Aug 11 '15 at 13:33

2 Answers2

0
for(String text : textList){
    String[] parts = text.split("|");
    String part1 = parts[0]; // abc, def
    String part2 = parts[1]; // 123, 456
    alphabet.add(part1);
    numbers.add(part2);
}
Carnal
  • 21,744
  • 6
  • 60
  • 75
0

But before split check textList is contain "|"

for(int i = 0; i< textList.size(); i++){
  String[] arr = textList.get(i).spit("|");
  alphabet.add(arr[0]);
  numbers.add(arr[1]);
}
Pavya
  • 6,015
  • 4
  • 29
  • 42