|
|
|
|
复制本帖HTML代码
|
高亮:
今天贴
X 昨天贴
X 前天贴
X |
因为是有序的
import java.util.LinkedHashMap;
import java.util.Map;
public class TestGeneral {
public static void main(String[] args) {
//store orignal User and Country
Map<String , String> hmOriginal = new LinkedHashMap<String , String>();
hmOriginal.put("John", "Canada");
hmOriginal.put("Bob", "USA");
hmOriginal.put("Tom", "USA");
hmOriginal.put("Alice", "Canada");
hmOriginal.put("Alan", "Canada");
hmOriginal.put("Peter", "UK");
//store Updated data
Map<String , String> hmUpdated = new LinkedHashMap<String , String>();
for (Map.Entry<String, String> entry : hmOriginal.entrySet())
{
String sName = entry.getKey();
String sCountry = entry.getValue();
if( !hmUpdated.containsValue(sCountry))
{
hmUpdated.put(sName, sCountry);
}
}
System.out.println("Original data is :"+hmOriginal );
System.out.println("Updated data is :"+hmUpdated );
}
}
.
|
欢迎来到华新中文网,踊跃发帖是支持我们的最好方法! |
|
|