简体   繁体   English

如何存储此列表并将它们与Java建议进行比较?

[英]How to store this lists and 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 moment I have stored my two lists as ArrayList and I am comparing them with removeAll applied on the first list. 目前,我将两个列表存储为ArrayList,并将它们与应用于第一个列表的removeAll进行比较。

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. 基本上,您可以使用titles.keySet()方法获取所有标题的titles.keySet() 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. 但是您必须小心直接从keySet删除值,因为某些映射可能不支持它。 May be you better iterate on all values from titlesToRemove and remove each one using remove method on map. 可能是您更好地迭代了titlesToRemove所有值,并使用地图上的remove方法删除了每个值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM