Description: Take out the non-DataTime in cp. Is the following code reasonable? Is there any concurrency problem with deviceDataMap?
Map<String,Map<String,String>> deviceDataMap = new HashMap<>();
String cp = "DataTime=20040506010101;SB1-RT=1.1;SB2-RT=2.1";
List<String> cpValusList = Arrays.asList(cp.split(";"));
cpValusList.stream().filter(item -> !item.contains("DataTime=")).forEach(item ->{
String deviceId = item.substring(0,item.indexOf("-"));
if(!deviceDataMap.containsKey(deviceId)){
Map<String,String> oneDeviceIdValusMap = new HashMap<>();
List<String> deviceIdValueList = Arrays.asList(item.split(","));
deviceIdValueList.forEach(value->{
String[] temp = value.split("=");
oneDeviceIdValusMap.put(temp[0], temp[1]);
});
deviceDataMap.put(deviceId, oneDeviceIdValusMap);
}
});
Parallel stream is a stream that divides the content into multiple data blocks and uses different threads to process each data block separately
There should be no concurrency issues in the above code. It seems that I still don’t understand the principle of java8 stream》》》》http://blog.csdn.net/sunjin94...