Results 1 to 5 of 5
- 01-03-2013, 09:02 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 2
- Rep Power
- 0
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?
- 01-03-2013, 10:02 AM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
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!.gif)
- 01-03-2013, 10:24 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,375
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-03-2013, 11:24 AM #4
Re: How to store this lists and still be able to compare them?Java advice?
Why do they call it rush hour when nothing moves? - Robin Williams
- 01-03-2013, 05:55 PM #5
Member
- Join Date
- Jan 2013
- Posts
- 2
- Rep Power
- 0
Re: How to store this lists and still be able to compare them?Java advice?
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
-
VERY new to Java, need help with linked lists?
By seven in forum New To JavaReplies: 2Last Post: 02-29-2012, 02:56 AM -
Java lists
By BobswYourUcle in forum New To JavaReplies: 1Last Post: 04-26-2011, 03:46 PM -
Compare two lists of number - what numbers arent there
By Bishop609 in forum New To JavaReplies: 5Last Post: 02-18-2009, 01:22 AM -
Compare lists
By JavaNoob in forum New To JavaReplies: 2Last Post: 08-08-2007, 03:11 PM -
how to compare 2 vector lists?
By oregon in forum New To JavaReplies: 2Last Post: 07-25-2007, 08:25 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks