加油,新时代打工人!
java
import org.junit.jupiter.api.Test;
import org.omg.CORBA.StringDefIRHelper;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.util.ObjectUtils;
import sun.security.util.AuthResources_it;
import java.util.*;
@SpringBootTest
class InterfacesApplicationTests {
@Test
void contextLoads() {
}
public static void main(String[] args) {
HashMap<String,String> map =new HashMap<>();
HashMap<String,String> map1 =new HashMap<>();
map.put("SSTYPE","1");
map.put("SSCODE","11");
map.put("SSNAME","小明");
map.put("SSJB","2");
map1.put("SSTYPE","1");
map1.put("SSCODE","11");
map1.put("SSNAME","小明");
map1.put("SSJB","2");
List<HashMap<String,String>> map2 =new ArrayList<>();
map2.add(map);
map2.add(map1);
// System.out.println("方式二>>map.entrySet().stream.forEach()遍历---Stream流遍历");
// for(HashMap<String,String> map3 :map2){
// map3.entrySet().stream().forEach((Map.Entry<String,String> entry) -> {
// System.out.print(entry.getKey());
// System.out.println(entry.getValue());
//
// });
// }
int [] index={0};
System.out.println("方式一>>map.entrySet().stream.forEach()遍历---Stream流遍历");
for (int j = 0; j < map2.size(); j++) {
HashMap<String,String> map4 =new HashMap<>();
// Iterator<Map.Entry<String,String>> it = map2.get(j).entrySet().iterator();
// while (it.hasNext()){
// Map.Entry<String,String> itEntry = it.next();
// map4.put(itEntry.getKey() + j,itEntry.getValue());
// it.remove();
// }
map2.get(j).entrySet().stream().forEach((Map.Entry<String,String> entry) -> {
System.out.println("索引"+index[0]);
if((("SSTYPE").equals(entry.getKey())) && ("1".equals(entry.getValue()))){
map4.put(entry.getKey(),entry.getValue());
}else{
map4.put(entry.getKey()+""+ index[0],entry.getValue());
}
index[0]++;
});
// System.out.println(map4.toString());
}
// System.out.println("map.keySet().stream.forEach()遍历---Stream流遍历");
// map.keySet().stream().forEach(key -> {
// System.out.println(map.get(key));
// });
}
}