Set the difference set ---- candidates for missing exams

Source: Internet
Author: User
package cn.cqu.huang;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class SetDemo {
public static void main(String[] args) {
String [] A = {"zhangsan", "Lisi", "wangwu", "zhaoliu", "qianqi"}; // All candidates
String [] B = {"zhangsan, Chinese, 80 ",
"Zhangsan, English, 89 ",
"Lisi, mathematics, 69 ",
"Lisi, English, 99 ",
"Zhaoliu, mathematics, 78"}; // student transcript that has taken the test
// Which candidates are missing?
Set<String> sa = new HashSet<String>();
for(int i=0;i<a.length;i++){
sa.add(a[i]);
}
Set<String> sb = new HashSet<String>();
for(int i=0;i<b.length;i++){
sb.add(b[i].split(",")[0]);
}
SA. removeall (SB); // The difference set of the Set
// Traverse the remaining elements in SA, that is, those who have not taken the test
Iterator<String> it = sa.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.