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!