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:java.util.NoSuchElementException... 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"));
        sc.useDelimiter("\n");
        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()) {
        ll.add(sc.next());  
        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
           ss.useDelimiter("/");
            while (ss.hasNext()) {
            st.add(sc.next());  
          System.out.println(s); //Just printing the entries..Is further split possible in here?
}

Deco,
Here's a wee hint... why 2 lists?
Wouldn't a Place class be simpler, and more flexible?class Place {
   public String city;
   public String state;
   Place(String citySlashState) {
      String[] s = citySlashState.split("/");
      this.city = s[0];
      this.state = s[1];
List<Place> places = new ArrayList<Place>;... just a suggestion...

Similar Messages

  • How to split a "project" (movie) into two separate projects.

    After converting two Hi-eight tapes into digital format for use with iMovie 10.0.3 (?), I created a movie called "Japan 1994" , complete with titles, imported still photos, etc. But it was over 2 hours long. (My wife considers any movie longer than 29 minutes 59 seconds as cruel and unusual punishment under the U.S. constitution). So I went to Imovie "Help" .....Hah!!!, surfed the web with my problem, with further frustration. So, I devised my own method:
      1. Created two new (empty) movies, "Nihon 1" and "Nihon 2" (Nihon=Japan, in Japanese)
    2. In  "Japan 1994", found a convenient break point rougly half way through, shift selected several clips up to the half way point.
    3. copied all of these at one time (command C)
    4. Opened "Nihon 1" and pasted (command V) these clips into this project.
    5. Repeated steps 2, 3, 4 for the second "half" (into "Nihon 2")
    All of this produced two separate projects of around 1 hour each. Added appropriate titles at the beggining and end of each of the new movies.
    Worked like a charm.
    Hope this helps other users of iMoive 10. (whatever).
    lawrence268

    I have a sandwich. I have been searching how to split the sandwich but it seems you don't split a sandwich. Someone said look in a draw for a tool or something!
    Wow.
    There are lots of ways to do what you're asking besides what has been said. You can double click the clip in the Browser. Set In & Out points in the viewer and add the Clip to the sequence. No need to split or cut anything in the sequence.
    You really need to learn a bit more before you continue cause this is a pre-noob question. I don't really know how to categorise it.

  • Can I use my 2TB WD My Book Essential for the Time Machine feature on the MacBook as well as two other Windows computers (one running 7 and one with Vista)?

    Can I use my 2TB WD My Book Essential for the Time Machine feature on the MacBook as well as to store information from two other Windows computers (one running 7 and one with Vista)?

    Yes you can but you need to partition the drive into at least 2 separate drives.
    To do that you need to use a Windows PC to do the first partitioning. Say you split the drive into two partitions each 1TB (or close to 1TB) each.
    Partition fand format both partitions on a Win PC as one NTFS and the other FAT32.
    Then move it to the Mac and Reformat the FAT32 partition Mac Extended (Journaled) with a GUID Partition Table.
    I have that same drive and that is what I did originally with it. I now have it just for the Mac as I have other externals for the Win systems.
    Good Luck.

  • How can I produce two outputs of the same project

    Dear Sir,
    My aim is to produce two outputs of the same master project,
    HTML help and Webhelp each one will be used differently in my
    compnay.
    Producing two outputs is fine but the problem was that
    external links are done differently for HTML help and Webhelp and
    as I Knew from you that this can be solved using conditional tags.
    Actually I am new to conditional tags and I don't know how to
    use them. Could you please help me to do this or recommend a link
    on how to use condtional tags to produce different outputs.
    Thank you very very much

    Hi there ahlam323
    See if the link below helps any. Some goober wrote something
    on it.
    Click
    here to read the goober's guide
    Cheers... Rick

  • How can I split a QuickTime file in two?

    8/21/2006. How can I split a QuickTime file in two? I saved a two hour videotape converted by PYRO A/V LINK to iBook G4 combo into a file of 24.5 Gb, and I saved to QuickTime into 536 mgs. Of course, it took half a day. When I went to copy it as video (536 mgs) onto a CD of 700 mg capacity, Toast 7 said it required 1100 mgs and couldn't do it. I have QuickTime Pro, got just recently. I would be very happy to learn how to split it, so to copy each of the split pieces onto 2 CD's, for my own purposes. Many, many thanks. Chuck Yopst. [email protected] 847-394-5621 Moutn Prospect, IL (nw Chicago suburb)

    Wednesday, 10:35 am CDT, 30 August 2006
    Kirk, Thanks for your post Monday 8/21. Interesting how things worked out. I split the OuickTime file--of my retired uncle Church of the Brethren pastor's 50th wedding anniversary, and came up with two folders. Each contained four more folders, and inside folder Mvseg was file Avseq.dat which contained the video material and, when double clicked, started playing that half of the story on Windows 98SE. It just so happens that my uncle's PC operating system is a Windows 98SE. All this from QuickTime 7.0 which Windows 98SE would play the audio but not the video. Then a week later, yesterday in fact, in looking through iDVD help I found your solution, which heretofore I had no idea of. I had to go into System Preferences--Hardware--CDs & DVDs, and set these for "Open with 'Ask what you want to do'." The factory settings were to "open these when inserted" without that "Ask"ing. So then I was able and did follow your solution and it worked, but as a single QuickTime file, playable on Windows XP and Windows 2000 and Macintosh but not Windows 98SE. So everything worked out well. And thank you again. Chuck Y

  • How to use Vector or other ArrayList etc to store my JTree??

    How to use Vector or other ArrayList etc to store my JTree??
    Dear friends,
    I have following I posted before, but not get satisfactory answer, so I modify and repost again here.
    I have following code can add classes and students in the JTree,
    in class Computer Science, it has student Bill Brien,
    in Math, no,
    Then I I add Student Nancy, Laura, Peter into Computer Science Class,
    add AAAA, BBB, CCC into Math class,
    I create a new class called Chemistry, then I add DDD int Chemistry;
    so this JTree is dynamically changed,
    [1]. How can I dynamically save my current JTree with all above tree structure and its nodes in a Vector or ArrayList(not sure which one is best)??
    see code below:
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    public class ModelJTreeTest extends JFrame {
      private JTree tree;
      private DefaultTreeModel model;
      private DefaultMutableTreeNode rootNode;
      public ModelJTreeTest() {
        DefaultMutableTreeNode philosophersNode = getPhilosopherTree();
        model = new DefaultTreeModel(philosophersNode);
        tree = new JTree(model);
        JButton addButton = new JButton("Add Class/Students");
        addButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            addPhilosopher();
        JButton removeButton = new JButton("Remove Selected Class/Students");
        removeButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            removeSelectedPhilosopher();
        JPanel inputPanel = new JPanel();
        inputPanel.add(addButton);
        inputPanel.add(removeButton);
        Container container = getContentPane();
        container.add(new JScrollPane(tree), BorderLayout.CENTER);
        container.add(inputPanel, BorderLayout.NORTH);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(400, 300);
        setVisible(true);
      private void addPhilosopher() {
        DefaultMutableTreeNode parent = getSelectedNode();
        if (parent == null) {
          JOptionPane.showMessageDialog(ModelJTreeTest.this, "Select Class", "Error",
              JOptionPane.ERROR_MESSAGE);
          return;
        String name = JOptionPane.showInputDialog(ModelJTreeTest.this, "Add Class/Students:");
        model.insertNodeInto(new DefaultMutableTreeNode(name), parent, parent.getChildCount());
      private void removeSelectedPhilosopher() {
        DefaultMutableTreeNode selectedNode = getSelectedNode();
        if (selectedNode != null)
          model.removeNodeFromParent(selectedNode);
      private DefaultMutableTreeNode getSelectedNode() {
        return (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
      private DefaultMutableTreeNode getPhilosopherTree() {
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Students");
        DefaultMutableTreeNode ancient = new DefaultMutableTreeNode("Computer Science");
        rootNode.add(ancient);
        ancient.add(new DefaultMutableTreeNode("Bill Brian"));
        DefaultMutableTreeNode math = new DefaultMutableTreeNode("Maths");
        rootNode.add(math);  
        DefaultMutableTreeNode physics = new DefaultMutableTreeNode("Physics");
        rootNode.add(physics);
        return rootNode;
      public static void main(String args[]) {
        new ModelJTreeTest();
    }the actual Tree dynamically created somehow looks like following:
                             |            1.Peter
                             |---CS---    2. Nancy
                             |            3. Laura
                             |            4.Brian
                             |
    Root(University): -------|---Math- 1.AAA
                             |            2.BBB
                             |            3.CCC
                             |
                             |
                             |---Chemistry- 1. DDDThanks a lot
    Good weekends

    you can't directly store a tree in a list.Ummm... Just to be contrary... Yes you CAN store a tree in a table.... In fact that's how the windows file system works.
    Having said that... you would be well advised to investigate tree data-structures before resorting to flattening a tree into a list.
    So... Do you have a specific requirement to produce a List? Your umming-and-erring about Vector vs ArrayList makes it sound like you're still at the stage of choosing a datastructure.
    Cheers. Keith.

  • Splitting one photo book into two?

    Hi, I have prepared one photo book (project) with iPhoto using the maximum of 100 pages (3 weeks US!!). Now, a friend shared his pics with me that I'd like to add. Can I split the one book in two with say 50 pages and continue addingnew pages with the spliited ones?
    Plus: Can I move complete pages from one iPhoto book to another project (book)?
    Thx for your help!
    Frank

    Select the book in the left hand pane and type Command+D (duplicate).  You can then modify each of the copies as needed.
    OT

  • Split one salesorder item into two items in delivery

    We want to split one salesorder item into two different items in the same delivery.
    This is because we will pick the material from two different storage locations.
    Any user-exit to use for solving this?
    Best regards,
    Terje

    Hi,
    We are not using batch management.
    I have looked into the foreign trade/customs standard functionality in SAP, but I can not see that them difference in stock in SAP what is duty paid or not.
    We need to have documentation in the system for the custom goverement for what stock is duty paid and not.
    For the same material we can have stock which are duty paid and not duty paid. This is decided when we do the goods receipt.
    For stock coming from Asia, it is profitable to have this on not duty paid stock since we are exporting it back to Europe and Asia later.
    We will send import and export EDI messages to a third party custom application handling all the papers with the custom goverement.
    The only we need to make track on in SAP is the stock for what is duty paid and not.
    In some situations we need to take stock from both duty paid stock and not duty paid stock when we deliver the same material to a customer. Therefor I asked the question of splitting one delivery item into two items.
    Best regards,
    Terje

  • Stored Procedure - Split one Input Paramater into two Paramater

    What is expected from me
    1) I am getting a input parameter as a string (url+id)with two delimiters(, and |) i.e 'html\abc.com,http\efc.com|112'
    Logic: If ID is not in the table or if ID is not there in input parameter then return null
    else
    send ID and URL from the table
    The way I am tackling aforesaid as I am new in Oracle PL/SQL
    1) I have two separate split function one to tackle , (comma) other to tackle |(pipe) which i got from NET
    2) I am creating 2 table with 2 columns (ID(identity),val)
    3) I am splitting input parameter and pushing result in first table where ID will always be second record
    so if count(*) = 1
    then return nothing (as there is no ID to map in the table)
    else
    4) splitting first row and pushing result in second table and then mapping with the table if its there then returning the val back...
    Here is the code Please let me know where i am going wrong?? where i have to correct??
    CREATE OR REPLACE
    PROCEDURE ap_dbi_ps_PM_Search
    v_PAGE_CTX IN VARCHAR2,
    v_CTX_ID IN NUMBER DEFAULT NULL ,
    v_Count IN NUMBER DEFAULT NULL ,
    cv_1 IN OUT SYS_REFCURSOR )
    AS
    ---tblPM table 2 columns id (idendity) and val
    CREATE SEQUENCE tb1PM_id START WITH 1 INCREMENT BY 1;
    CREATE TABLE tb1PM
    ( id NUMBER(10,0) PRIMARY KEY, Val VARCHAR2(400)
    CREATE OR REPLACE TRIGGER tb1PM_id_TRG BEFORE
    INSERT ON tb1PM FOR EACH ROW BEGIN
    SELECT tb1PM_id.NEXTVAL INTO :NEW.id FROM DUAL;
    END;
    -- tblPM1 table 2 columns id (idendity) and val
    CREATE SEQUENCE tb1PM1_id START WITH 1 INCREMENT BY 1;
    CREATE TABLE tb1PM1
    ( id NUMBER(10,0) PRIMARY KEY, Val VARCHAR2(400)
    CREATE OR REPLACE TRIGGER tb1PM1_id_TRG BEFORE
    INSERT ON tb1PM1 FOR EACH ROW BEGIN
    SELECT tb1PM1_id.NEXTVAL INTO :NEW.id FROM DUAL;
    END;
    --Split the input paramater and push result in tblPM*
    INSERT
    INTO tb1PM
    val
    (SELECT * FROM TABLE ( CAST(split('v_PAGE_CTX') AS split_tbl))
    DECLARE
    v_Count NUMBER
    10,0
    DECLARE
    V_CTX_ID NUMBER
    10,0
    SET V_CTX_ID =
    (SELECT DISTINCT TO_NUMBER(val) FROM tb1PM WHERE id = 2
    SET v_Count =
    (SELECT COUNT(*) FROM tb1PM
    BEGIN
    IF v_Count = 2 THEN
    INSERT
    --Split URL's from tblPM*
    INTO tb1PM1
    val
    (SELECT *
    FROM TABLE(splitcomma(
    JOIN(CURSOR
    (SELECT val FROM tb1PM WHERE id =1
    OPEN cv_1 FOR SELECT PAGE_DISPLAY_URL,
    CTX_ID FROM portal_mapping WHERE CTX_ID = V_CTX_ID group by V_CTX_ID HAVING v_PAGE_DISPLAY_URL IN
    ( SELECT DISTINCT val FROM tb1PM1
    RETURN;
    DROP TABLE tb1PM;
    DROP TRIGGER tb1PM_id_TRG;
    DROP SEQUENCE tb1PM_id;
    DROP TABLE tb1PM1;
    DROP TRIGGER tb1PM1_id_TRG;
    DROP SEQUENCE tb1PM1_id;
    ELSE
    EXCEPTION
    WHEN OTHERS THEN
    -- NULL;
    END IF;
    END;
    show errors;
    ERROR which I am getting is
    Warning: execution completed with warning
    PROCEDURE ap_dbi_ps_PM_Search Compiled.
    24/1 PLS-00103: Encountered the symbol "CREATE" when expecting one of the following:
    begin function pragma procedure subtype type <an identifier>
    <a double-quoted delimited-identifier> current cursor delete
    exists prior external language

    You have to learn how to write the procedure before you could write one. I just corrected the syntax errors. I did not paid attention to your logical errors. This one compiled without errors other than the table does not exists. My doubt is If you are creating the tables in the procedure, how will the tables already have data?
    CREATE OR REPLACE PROCEDURE ap_dbi_ps_PM_Search ( v_PAGE_CTX IN VARCHAR2, v_CTX_ID IN NUMBER DEFAULT NULL , v_Count IN NUMBER DEFAULT NULL , cv_1 IN OUT SYS_REFCURSOR )
    AS
    BEGIN
    ---tblPM table 2 columns id (idendity) and val
    execute immediate 'CREATE SEQUENCE tb1PM_id START WITH 1 INCREMENT BY 1';
    execute immediate 'CREATE TABLE tb1PM ( id NUMBER(10,0) PRIMARY KEY, Val VARCHAR2(400) )';
    execute immediate ' CREATE OR REPLACE TRIGGER tb1PM_id_TRG BEFORE INSERT ON tb1PM FOR EACH ROW BEGIN  SELECT tb1PM_id.NEXTVAL INTO :NEW.id FROM DUAL; END';
    -- tblPM1 table 2 columns id (idendity) and val
    execute immediate 'CREATE SEQUENCE tb1PM1_id START WITH 1 INCREMENT BY 1';
    execute immediate 'CREATE TABLE tb1PM1 ( id NUMBER(10,0) PRIMARY KEY, Val VARCHAR2(400) )';
    execute immediate 'CREATE OR REPLACE TRIGGER tb1PM1_id_TRG BEFORE INSERT ON tb1PM1 FOR EACH ROW BEGIN SELECT tb1PM1_id.NEXTVAL INTO :NEW.id FROM DUAL; END';
    --Split the input paramater and push result in tblPM
    execute immediate 'INSERT INTO tb1PM ( val ) (SELECT * FROM TABLE ( CAST(split( ''v_PAGE_CTX '') AS split_tbl)) )';
    -- SET V_CTX_ID = (SELECT DISTINCT TO_NUMBER(val) FROM tb1PM WHERE id = 2 ) ;
    select distinct to_number(val)  into v_ctx_id from tb1PM where id = 2;
    -- SET v_Count = (SELECT COUNT(*) FROM tb1PM ) ;
    select count(*) into v_count from tb1PM;
    IF v_Count = 2 THEN
    INSERT INTO tb1PM1 ( val )
        (SELECT * FROM TABLE(splitcomma( JOIN(CURSOR (SELECT val FROM tb1PM WHERE id =1 ) ) ) ) );
    OPEN cv_1 FOR SELECT PAGE_DISPLAY_URL, CTX_ID FROM portal_mapping WHERE CTX_ID = V_CTX_ID group by V_CTX_ID HAVING v_PAGE_DISPLAY_URL IN
        ( SELECT DISTINCT val FROM tb1PM1 );
    RETURN;
    END IF;
    END;
    EXCEPTION
    WHEN OTHERS THEN
      DROP TABLE tb1PM;
      DROP TRIGGER tb1PM_id_TRG;
      DROP SEQUENCE tb1PM_id;
      DROP TABLE tb1PM1;
      DROP TRIGGER tb1PM1_id_TRG;
      DROP SEQUENCE tb1PM1_id;
    END;

  • Split one Post OFfice in two parts

    Hi there!
    I have problems with my Poa, because I'm having problems with I/O. Despite of all,
    my POA is about 250 GB and I think that it's pretty big. So I have a lot of "batch users"
    that are receiving a lot of emails with low priority, and I am thinking in split my post office
    in two parts:
    1) personal/phyisical users (humans): my actual post office. With SAN storage (expensive)
    and priority backups.
    2) non humans: batch users, iScsi storage , cheap and only a backup in saturday.
    The question is: I saw that there is a procedure to move an user from one post office
    to another, but these users have a lot of proxy accesses and rules. These options
    are saved in the move? I mean, there are rules for forward emails to users in post office 1).
    Does the system relocalize these users from post office 2) in post office 1) ?
    I know that the best test would test with one test user... but just in case.
    Thank you all!

    In article <[email protected]>,
    Antoniogutierrez wrote:
    > I have problems with my Poa, because I'm having problems with I/O.
    > Despite of all,
    instead of putting a lot of effort into splitting this little
    PostOffice into two, how about looking at the I/O challenges as fixing
    them might be much more effective. Might even help you elsewhere as
    well.
    What plateform are you running on? Hypervisor? What is the storage
    access type?
    What are the particular I/O challenges you are hitting?
    Andy of
    http://KonecnyConsulting.ca in Toronto
    Knowledge Partner
    http://forums.novell.com/member.php/75037-konecnya
    If you find a post helpful and are logged in the Web interface, please
    show your appreciation by clicking on the star below. Thanks!

  • How to split an A3 page to two A4 pages?

    Hello,
    I need to scan an A4 booklet to upload, but I cannot cut it in order to have a bunch of pages to scan.
    Therefore I'm scanning it spread on a fladbed scanner, resulting in a series of A3 spreads.
    How can I split these A3 pages into two A4 pages each, preferrably in batch mode, so as not to repeat this work? Using the crop tool is too slow.
    Thanks.

    This requires I do at least 3 actions per page, and with a few dozen to a few hundred pages to do, it's way too slow, not to mention the fact that doing each by hand will probably cause the crops to be uneven.
    Is there any way to automate it?
    Thanks anyway,

  • How i can split a pdf doc to two?

    is it possible to split a pdf document to two and if yes how i can do it?

    You can't do it with Reader. You need Acrobat for that.

  • How do I split up a project into two or more projects?

    How do I split up a project into two or more projects?

    Select the Images you want to put in the new Project and then run "File➞New➞Project" and check "Move selected items to new project".

  • Middle keys and number line on keyboard produce two characters

    When I press the middle keys (asdf...) or the number line (1234...) on the keyboard of our MacBook it produces two characters - one number and one letter -  instead of just the correct one.  The characters produced on both lines are identical and look like this:   a1s2d3f4g5h6j7k8l9 a1s2d3f4g5h6j7k8l9.  Can anything be done?   It is driving me nuts!

    Hey siirilee,
    Thanks for the question. The following article may help to resolve your issue. You may want to refer to the "Some keys don't work as expected" section:
    One or more keys on the keyboard do not respond
    http://support.apple.com/kb/TS1381
    Thanks,
    Matt M.

  • Splitting my Adobe ID into two accounts / transfering registrations

    How can I split my Adobe ID into two accounts, and transfer registrations from one to another?
    Background: our company has split into two companies.

    You'll need to contact web chat:
    Adobe ID, sign in, and account help

Maybe you are looking for

  • What is the "Progid" of Adobe Acrobat reader.

    hi, I am trying to work on OLE invoke the Acrobat Reader File through ole container, just as to invode and create object for word we are using create_obj('word.application') . So the 'word.application' is stored in progid of registroy file. So , i am

  • Problem with special characteres

    Hi. I have a problem with java. I�m making an application that works with special characters and displays correctly on my local machine, as I use escape characters such as ì for �. The problem is when I deploy the application on a unix machine. All o

  • With 7.1 "Share WiFi Settings" no longer works for A3 Pioneer Speaker setup

    I am nolonger able to link my Pioneer A3 Speaker with my WiFi network by plugging it into my iPhone or iPad, no message asking "Share the WiFi Settings". I have used various cables, re-booted WiFi and devices etc so conclude either my A3 has suddenly

  • Document details for Project & WBS

    Hi, Is there any standard report available which shows all the document nos. for the project or wbc, like inquiry no., quotation no. Thank you, Prashant

  • "Name on the Security Certificate is Invalid or Does not Match..." using Outlok 2007 w/ Exchange 2007

    Good afternoon! We just completed our Exchange 2007 implementation (migration from Exchange 2003... a fun romp of 24 straight hours for the final push) and noticed an error that only occurs on Outlook 2007 clients connecting to the Exchange 2007 serv