一、list转为map
@Test public void test010(){ Map<String,String> map = Maps.newHashMap(); List<BackupQueueManage> backups = Lists.newArrayList(); BackupQueueManage queue = new BackupQueueManage(); queue.setQueueName("oracle-090909"); queue.setDbType("DB2"); queue.setLinkScriptId("1"); queue.setScheduleType("0"); backups.add(queue); backups.forEach(e ->{ map.put("queueName",e.getQueueName()); map.put("DbType",e.getDbType()); map.put("LinkScriptId",e.getLinkScriptId()); map.put("ScheduleType",e.getScheduleType()); }); System.out.println(map); }
运行结果
{ScheduleType=0, LinkScriptId=1, queueName=oracle-090909, DbType=DB2}
二、map转为list
@Test public void test010(){ Map<String,String> map = Maps.newHashMap(); map.put("queueName","oracle-090909"); map.put("DbType","DB2"); map.put("LinkScriptId","1"); map.put("ScheduleType","0"); List<Map<String,String>> results = Lists.newArrayList(); map.forEach((k,v) -> { Map<String,String> tempMap = Maps.newHashMap(); tempMap.put(k,v); results.add(tempMap); }); System.out.println(results); }
运行结果
[{ScheduleType=0}, {LinkScriptId=1}, {queueName=oracle-090909}, {DbType=DB2}]