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 moment I have stored my two lists as ArrayList and I am comparing them with removeAll applied on the first list.
How can I store the first list so that it has the requested connection with the file name for every title and still be able to compare it with the second list?
You can use maps for that:
Map<String, String> titles = new HashMap<String, String>();
titles.put("title1", "filename1");
titles.put("title1a", "filename1a");
...
titles.put("title5", "filename5");
Basically you can get set of all titles using titles.keySet()
method.
If you need to delete some titles using list you can following:
List<String> titlesToRemove = Arrays.toList("title1", "title2", "title3");
titles.keySet().removeAll(titlesToRemove);
But you must be careful with deleting values from keySet
directly because some map may not support it. May be you better iterate on all values from titlesToRemove
and remove each one using remove
method on map.