Results 1 to 5 of 5
  1. #1
    Miday8 is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Exclamation How to store this lists and still be able to compare them?Java advice?

    Could you plese give me some adivce on this problem:

    I have two lists of titles of the type:

    title1____title1
    title1a___title2
    title1c___title3
    title1b___title4
    title2____title3
    title4
    title5
    and the first list must have attached to it a list of file names. How can I store this two lists so that I can compare them?

    At the momet I have stored my two lists as ArrayList and I am comparing them with remveAll applied on the first list.

    How can I store the first list so that it has the requested connection with the filename for every title and still be able to compare it with the second list?

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: How to store this lists and still be able to compare them?Java advice?

    There are many possibilities depending on your exact requirement.
    - One would be to use a Hashtable<..., ...> instead of a normal ArrayList to map single elements to a filename.
    - Another solution would be to use the HAshtable to refer to a newly created item that contains the additional information (you need to define a new class e.g. InfoTitle)
    - The most flexible one would be to create own list items which implement the Comparable<...> interface and (as it is an own class you define) may contain any title, filename or other information for a given title. You then need to implement the compareTo(...) method and this method will determine how one item compares to the other.

    Those are my two cents I guess. ;)
    I like likes!

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,783
    Blog Entries
    7
    Rep Power
    21

    Default Re: How to store this lists and still be able to compare them?Java advice?

    Would a Map<String, Set<String>> do the job?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: How to store this lists and still be able to compare them?Java advice?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Miday8 is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: How to store this lists and still be able to compare them?Java advice?

    Quote Originally Posted by JosAH View Post
    Would a Map<String, Set<String>> do the job?

    kind regards,

    Jos
    Hello,

    For anyone who may encounter the same problem, this solution worked for me:

    Map<String, String> titles = new HashMap<String, String>();

    And the compare:

    List<String> titlesToRemove = Arrays.toList("title1", "title2", "title3");
    titles.keySet().removeAll(titlesToRemove);

    Thanks to:Nikita Beloglazov
    string - How to store this lists and compare them Java advice? - Stack Overflow

Similar Threads

  1. VERY new to Java, need help with linked lists?
    By seven in forum New To Java
    Replies: 2
    Last Post: 02-29-2012, 03:56 AM
  2. Java lists
    By BobswYourUcle in forum New To Java
    Replies: 1
    Last Post: 04-26-2011, 04:46 PM
  3. Compare two lists of number - what numbers arent there
    By Bishop609 in forum New To Java
    Replies: 5
    Last Post: 02-18-2009, 02:22 AM
  4. Compare lists
    By JavaNoob in forum New To Java
    Replies: 2
    Last Post: 08-08-2007, 04:11 PM
  5. how to compare 2 vector lists?
    By oregon in forum New To Java
    Replies: 2
    Last Post: 07-25-2007, 09:25 PM

Tags for this Thread

Posting Permissions

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