方法
package com
public static void main(String[] args) {
List<String> list
List<String> list
for (int i =
list
list
}
getDiffrent(list
//輸出
}
/**
* 獲取連個List的不同元素
* @param list
* @return
*/
private static List<String> getDiffrent(List<String> list
long st = System
List<String> diff = new ArrayList<String>()
for(String str:list
{
if(!ntains(str))
{
diff
}
}
System
return diff;
}}
千萬不要采用這種方法
方法
package com
public static void main(String[] args) {
List<String> list
List<String> list
for (int i =
list
list
}
getDiffrent(list
//輸出
getDiffrent
//輸出
}
/**
* 獲取連個List的不同元素
* @param list
* @param list
* @return
*/
private static List<String> getDiffrent
long st = System
list
System
return list
}
/**
* 獲取連個List的不同元素
* @param list
* @param list
* @return
*/
private static List<String> getDiffrent(List<String> list
long st = System
List<String> diff = new ArrayList<String>()
for(String str:list
{
if(!ntains(str))
{
diff
}
}
System
return diff;
}}
很遺憾
public boolean retainAll(Collection<?> c) {
boolean modified = false;
Iterator<E> e = iterator()
while (e
if (!ntains(e
e
modified = true;
}
}
return modified;
}
無需解釋這個耗時是必然的
package com
public static void main(String[] args) {
List<String> list
List<String> list
for (int i =
list
list
}
getDiffrent(list
//輸出
getDiffrent
//輸出
getDiffrent
//輸出
}
/**
* 獲取連個List的不同元素
* @param list
* @param list
* @return
*/
private static List<String> getDiffrent
long st = System
Map<String
List<String> diff = new ArrayList<String>()
for (String string : list
map
}
for (String string : list
Integer cc = map
if(cc!=null)
{
map
continue;
}
map
}
for(Map
{
if(entry
{
diff
}
}
System
return list
}
/**
* 獲取連個List的不同元素
* @param list
* @param list
* @return
*/
private static List<String> getDiffrent
long st = System
list
System
return list
}
/**
* 獲取連個List的不同元素
* @param list
* @param list
* @return
*/
private static List<String> getDiffrent(List<String> list
long st = System
List<String> diff = new ArrayList<String>()
for(String str:list
{
if(!ntains(str))
{
diff
}
}
System
return diff;
}}
顯然
package com
public static void main(String[] args) {
List<String> list
List<String> list
for (int i =
list
list
}
getDiffrent(list
getDiffrent
getDiffrent
getDiffrent
getDiffrent total times
getDiffrent
getDiffrent
getDiffrent
}
/**
* 獲取連個List的不同元素
* @param list
* @param list
* @return
*/
private static List<String> getDiffrent
long st = System
Map<String
List<String> diff = new ArrayList<String>()
List<String> maxList = list
List<String> minList = list
if(list
{
maxList = list
minList = list
}
for (String string : maxList) {
map
}
for (String string : minList) {
Integer cc = map
if(cc!=null)
{
map
continue;
}
map
}
for(Map
{
if(entry
{
diff
}
}
System
return diff;
}
/**
* 獲取連個List的不同元素
* @param list
* @param list
* @return
*/
private static List<String> getDiffrent
long st = System
Map<String
List<String> diff = new ArrayList<String>()
for (String string : list
map
}
for (String string : list
Integer cc = map
if(cc!=null)
{
map
continue;
}
map
}
for(Map
{
if(entry
{
diff
}
}
System
return diff;
}
/**
* 獲取連個List的不同元素
* @param list
* @param list
* @return
*/
private static List<String> getDiffrent
long st = System
list
System
return list
}
/**
* 獲取連個List的不同元素
* @param list
* @param list
* @return
*/
private static List<String> getDiffrent(List<String> list
long st = System
List<String> diff = new ArrayList<String>()
for(String str:list
{
if(!ntains(str))
{
diff
}
}
System
return diff;
}}
這裡對連個list的大小進行了判斷
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27046.html