Tool class: An algorithm for finding the different data in two list arrays!

Source: Internet
Author: User

Find the algorithm for the different data in the two list array!

Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;

Public class Getlistdifferent {

Public static Boolean isdifferentwithlist (String URL, list<string> List) {
return list.contains (URL)? false:true;
}

/**
* @param list1
* @param list2
* @return
*/
Public static list<string> getdiffrent (list<string> list1, list<string> list2) {
Long st = System.nanotime ();
map<string,integer> Map = new hashmap<string,integer> (List1.size () +list2.size ());
list<string> diff = new arraylist<string> ();
For (String string:list1) {
map.put (string, 1);
}
For (String string:list2) {
Integer cc = Map.get (string);
if (cc!=null)
{
map.put (String, ++cc);
continue;
}
map.put (string, 1);
}
for (map.entry<string, integer> entry:map.entrySet ())
{
if (Entry.getvalue () ==1)
{
Diff.add (Entry.getkey ());
}
}
//System.out.println ("GetDiffrent3 total times" + (System.nanotime ()-st));
return diff;
}

}

Data structure is a course that our developers must learn, he is the soul of program design, software development of the necessary tools. I am not, recommend a reference to the data structure of the book: Min

Data structure problem set "C language Edition"

Tool class: An algorithm for finding the different data in two list arrays!

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.