Skip to main content

Posts

Showing posts with the label split

Array lists and string splitting(Java) [closed]

I am trying to read a text file, and read its contends. Easy enough, right? But the files contents read: Part1:Part2 Part1:Part2 I am trying to add the string(s) to a to an array list, with the following protocol: Add "Part1" to an arraylist called p1, then add "Part2" to an arraylist called p2. I need to go through the whole text file with multiple lines. How would I do so?

Java string splitting error

I need to split array of string and then save it into smaller string. Plz help me....what i am doing wrong..... for(int i=0; i<suburl.size(); i++){ String temp = suburl.get(i); String[] data = temp.split(" "); Log.i("DATA 0", data[0]); Log.i("DATA 1", data[1]); Log.i("DATA 2", data[2]); } here public static ArrayList<String> suburl = new ArrayList<String>(); where, suburl.get(0) = "alex 21 engineer" suburl.get(1) = "mike 22 lawyer" suburl.get(2) = "sunny 26 deisnger" suburl.get(3) = "kim 24 painter" and String[] data; But what i am getting error when splitting is ....... 01-19 20:35:09.820: E/AndroidRuntime(1672): Caused by: java.lang.ArrayIndexOutOfBoundsException 01-19 20:35:09.820: E/AndroidRuntime(1672): at flash.com.MainActivity.onCreate(MainActivity.java:119) 01-19 20:35:09.820: E/AndroidRuntime(1672): at android.app.Instrumentation.cal