6 Replies Latest reply on Mar 2, 2007 2:10 PM by 800308

    splitting an ArryList to produce two other ArrayLists

      Hello, I am still strying to figure this out. Thanks for the replies to the previous post. So I have an ArrayList now:
       ll = [New Mexcio/Albuquerque
      , California/Los Angeles, Illinois/Chicago, New York/New York, Arizona/Phoenix, Oregon/Portland]
      It consists of 6 entries and the goal is to make two separate ArrayLists holding states and cities separately. My idea was to iterate through the first ArrayList and do another split for each entry, putting the two tokens into two different ArrayLists each time.. I was trying to do all that in one for each loop only, but I dont think there is a way. I am copying the code, which throws a runtime exception:
      ... Any ideas welcome..

      import java.util.*;
      import java.io.*;
      public class ScannerFile { 
          public static void main(String[] args) throws Exception {
              Scanner sc = new Scanner(new File("statecity.txt"));
              List<String> ll = new ArrayList<String>();
              List<String> st = new ArrayList<String>(); //hold states only
              List<String> ct = new ArrayList<String>(); //hold cities only
            while (sc.hasNext()) {
              System.out.println(ll); //just printing
              System.out.println("    " +ll.size());//just printing
            for(String s:ll){
                Scanner ss = new Scanner(s); //Second Scanner to 
                  while (ss.hasNext()) {
                System.out.println(s); //Just printing the entries..Is further split possible in here?