在Java集合中将字符串与令牌和树集一起使用 [英] Using string to tokens and tree set together in Java collections
问题描述
嗨
我正在做一个使用Java清除垃圾邮件的项目.在这种情况下,我正在使用Java Collections(字符串到令牌).首先,我发送一组邮件(手动添加),这些邮件是由多个用户(例如:Peter,John,Raf,Sam等)发送的.然后,使用树集,我想创建一个垃圾邮件字典,这将有助于过滤垃圾邮件发送者.
1.如何在单个程序中实现令牌字符串和树集类的字符串
2.垃圾邮件字典(树集)应将名称与第一个程序(字符串到令牌)进行比较,并单独检索垃圾邮件发送者.例如,在第一个程序中,我有Peter,John,Raf和Sam.约翰和山姆是垃圾邮件制造者,我需要显示他们的名字.
3.输出必须为:
发件人列表:Peter,John,Raf,Sam
垃圾邮件发送者列表:John,Sam
请帮助我.
Hi
I am doing a project for spam removal using Java. In that, I am using Java Collections (string to tokens). First, I send a set of mails (adding manually ) which I are sent by multiple users (e.g.: Peter, John, Raf, Sam, etc.). Then, using a tree set, I want to create a spam dictionary and this will help filter the spammers.
1. How can I implement string to tokens and the tree set class in a single program
2. The spam dictionary (tree set) should compare the names with the first program (string to tokens) and retrieve the spammers alone. For example, in the first program I have Peter, John, Raf, and Sam. John and Sam are spammers, and I need to display their names.
3. The output must be:
List of Senders : Peter, John, Raf, Sam
List of Spammers: John, Sam
Please help me.
推荐答案
您可以使用集合将项目加载到其中,然后hashSet
非常适合联合和联接:
You can use sets to load the items into and then ahashSet
is great for unions and joins:
String all = "a b c d e f g h i j k l m n";
String bad = "x k c d";
Set<string> allSet = new java.util.HashSet<string>(
Arrays.asList(all.split(" ")));
Set<string> badSet = new java.util.HashSet<string>(
Arrays.asList(bad.split(" ")));
Set<string> allBad = new HashSet<string>(allSet);
allBad.retainAll(badSet);
System.out.println(allSet);
System.out.println(badSet);
System.out.println(allBad);
</string></string></string></string></string></string>
这篇关于在Java集合中将字符串与令牌和树集一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!