package com.atguigu.mvc.bean;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: ZZP
* @Date: Created in 21:46 2021/11/11
* @Version: 1.0
* @Description:
**/
public class main {
public static void main(String[] args) {
Map<String, String> friends_Name = new HashMap<String, String>();
friends_Name.put("x", "y");
friends_Name.put("a", "b");
friends_Name.put("c", "d");
friends_Name.put("e", "d");
friends_Name.put("f", "b");
friends_Name.put("m", "n");
Map<String, ArrayList<String>> friends_Name2 = new HashMap<String, ArrayList<String>>();
String entryName = null;
String entryFriends = null;
ArrayList<String> FriendsList = new ArrayList<String>();
ArrayList<String> FriendsList2 = new ArrayList<String>();
for (Map.Entry<String, String> entry : friends_Name.entrySet()) {
FriendsList.clear();
FriendsList2.clear();
entryFriends = entry.getKey();
entryName = entry.getValue();
if (friends_Name2.keySet().contains(entryName)) {
FriendsList2 = friends_Name2.get(entryName);
FriendsList2.add(entryFriends);
friends_Name2.put(entryName, (ArrayList<String>) FriendsList2.clone());
} else {
FriendsList.add(entryFriends);
friends_Name2.put(entryName, (ArrayList<String>) FriendsList.clone());
}
}
System.out.println(friends_Name2);
}
}
07-07
3361
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)