Tuesday, 15 January 2013

file - Read text and save some information in Java -



file - Read text and save some information in Java -

i have text formatted follow:

lorem ipsum word <tag> 1,2,3,4 </tag> dolor sit down amen

how can save "1,2,3,4" in arraylist?

here's can start with:

string str="lorem ipsum word <tag> 1,2,3,4 </tag> dolor sit down amen"; string tag=str.substring(str.indexof("<tag>") + "<tag>".length()); tag = tag.substring(0, tag.indexof("</tag>")).trim(); string[] ints = tag.split(","); list<integer> list = new arraylist<integer>(); (string s : ints) { list.add(integer.valueof(s)); } system.out.println(list);

note code not handle errors nor check if input string valid.

java file arraylist split

No comments:

Post a Comment