List的遍历

1.List>的遍历:

Map map =  new  HashMap(); 
 
     map.put( "1" "fds" ); 
     map.put( "2" "valu" ); 
     List> list =  new  ArrayList>(); 
     list.add(map); 
     for  (Map m : list){ 
       for  (String k : m.keySet()){ 
         System.out.println(k +  " : "  + m.get(k)); 
      
    
     }

 2.两个List>相互比较,有相同数据时某些字段相加减

 inOrderList与outOrderList放自己的所比较的数据,name,number,id为map的key值

for  ( int  i =  0 ; i < inOrderList.size(); i++) { //循环获取入库数据
         String number1 = String.valueOf(inOrderList.get(i).get( "number" ));
             String depotName1 = inOrderList.get(i).get( "name" );
             String proId1 = inOrderList.get(i).get( "id" );
             for  ( int  j =  0 ; j < outOrderList.size(); j++) { //循环获取出库数据
                  String number2 = String.valueOf(outOrderList.get(j).get( "number" ));
                  String depotName2 = outOrderList.get(j).get( "name" );
                  String proId2 = outOrderList.get(j).get( "id" );
                 if  (depotName1.equals(depotName2) && proId1.equals(proId2)) {
                     Integer sum =Integer.parseInt(number1) - Integer.parseInt(number2); //判断是否为同一条数据,同条数据数量相减
                     inOrderList.get(i).put( "number" , sum +  "" );
                 }
             }
         }


你可能感兴趣的:(java)