Results 1 to 4 of 4

Thread: ArrayList issue

  1. #1
    drogba123 is offline Member
    Join Date
    Mar 2011
    Posts
    29
    Rep Power
    0

    Default ArrayList issue

    hi,

    a1.add("every");
    a1.add("bobs");
    a1.add("three");
    a2.add("ev");
    a2.add("ob");

    for (String bigram1 : a2) {
    for (String words : a1) {
    if (words.contains(bigram1)) {
    if(test.containsKey(bigram1)){
    test.get(bigram1).add(words);
    }
    else {
    test.put(bigram1, new ArrayList<String>(a1));
    }
    }
    }
    }
    System.out.println(test);
    but it does not make any comparison

    {ev=[every, bobs, three], ob=[every, bobs, three]}

    displayed all values. what is wrong in this codes?thanks.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    Recommended reading:
    Code Conventions for the Java(TM) Programming Language: Contents
    How To Ask Questions The Smart Way
    SSCCE : Java Glossary

    We haven't the slightest clue what the variable test represents. This does look wrong though:
    Java Code:
    test.put(bigram1, new ArrayList<String>(a1));
    db

    edit And use code tags, not quote tags, to post code.

  3. #3
    drogba123 is offline Member
    Join Date
    Mar 2011
    Posts
    29
    Rep Power
    0

    Default

    hi db,

    thank for the reply

    HashMap<String, ArrayList<String>> test = new HashMap<String, ArrayList<String>>();

    ArrayList <String> a1 = new ArrayList<String>();
    ArrayList <String> a2 = new ArrayList<String>();

    test represent hashmap

    and a1 and a2 represent 2 arraylists

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default

    So, what does the code line I quoted do? What does it put into the Map?

    What are the contents of new ArrayList<String>(a1)

    db

Similar Threads

  1. sorting arraylist based on another arraylist
    By busdude in forum New To Java
    Replies: 4
    Last Post: 02-07-2011, 11:48 AM
  2. Replies: 7
    Last Post: 11-22-2010, 01:26 PM
  3. Replies: 19
    Last Post: 08-10-2010, 08:36 AM
  4. ArrayList issue
    By tomrobpowell in forum Eclipse
    Replies: 2
    Last Post: 05-08-2010, 07:04 AM
  5. Replies: 2
    Last Post: 04-21-2008, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •