You can use split()
method:
String s="Krakow#Poland#Warsaw";
String[] parts = s.split("#");
The output :
for (String i: parts)
System.out.println(i);
==>
run:
Krakow
Poland
Warsaw
BUILD SUCCESSFUL (total time: 0 seconds)
Вопрос
I got problem I try to split up text (orginal format is city#country#capitalcityname for example: Krakow#Poland#Warsaw) how can I split up text after # ? I want to put text after it into a table, is list a good idea ?
public class WordSearch {
ArrayList<String> list= new ArrayList<>();
public WordSearch(){
try {
File file = new File ("songs.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while((line = br.readLine()) != null) {
list.add(line);
// System.out.println(line);
}
} catch (IOException e) {
System.out.println(e.getLocalizedMessage());
}
}
public ArrayList<String> getList() {
return list;
}
}
To make it more clear I add visual example of table
Нет правильного решения
Другие советы
You can use split()
method:
String s="Krakow#Poland#Warsaw";
String[] parts = s.split("#");
The output :
for (String i: parts)
System.out.println(i);
==>
run:
Krakow
Poland
Warsaw
BUILD SUCCESSFUL (total time: 0 seconds)
You can use the split()
method.
String[] list = text.split("#");