list和list<map<String,object>>比较,不存在map的key赋值

package com;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;public class test {
public static void main(String[] args) throws ParseException {
    
     Map map = new HashMap<String, Object>();
        map.put("1", "fds");
        map.put("2", "valu");
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        list.add(map);
        for (Map<String, Object> m : list)
        {
          for (String k : m.keySet())
          {
            System.out.println(k + " : " + m.get(k));
          }

        }
        List user = new ArrayList();
        user.add(1);
        user.add(2);
        user.add(3);
        user.add(4);
      
        for(int  i=0;i<user.size();i++){
            String a= String.valueOf( user.get(i));
            boolean flag=map.containsKey(a);
            if(flag){
                System.out.println("存在");
            }else{
                System.out.println("不存在");
                map.put(a,"jiade");
            }
            
             for (Map<String, Object> m : list)
             {
               for (String k : m.keySet())
               {
                 System.out.println(k + " : " + m.get(k));
               }

             }
            
        }
}
posted @ 2017-09-15 15:49  烟雨观春柳  阅读(601)  评论(0编辑  收藏  举报