java中List Set Map使用

时间:2021-02-25 07:55:35
@Test
        public void run()
       {
              
              ArrayList<String> list= new ArrayList<String>();
              list.add( "美女");
              list.add( "帅哥");
              list.add( "芙蓉姐姐" );
               for (int i = 0; i < list.size(); i++) {
                     String str=list.get(i);
                     System. out.println(str);
              }
              System. out.println("==============================================" );
               for(String str:list)
              {
                     System. out.println(str);
                     
              }
              System. out.println("==================使用迭代器========================" );
              Iterator<String> it=list.iterator();
               while(it.hasNext())
              {
                     System. out.println(it.next());
                     
              }
       }
       
       
        @Test
        public void run1()
       {
              Set<String>set= new HashSet<String>();
              set.add( "aaaaaaaa");
              set.add( "bbbbbbbb");
              set.add( "cccccccc");
              set.add( "dddddddd");
              Iterator <String> iset=set.iterator();
               while(iset.hasNext())
              {
                     System. out.println(iset.next());
                     
              }
       }
        @Test
        public void run2()
       {
              
              Map<String,Integer> map= new HashMap<String,Integer>();
              map.put( "name", 1);
              map.put( "Height", 175);
              map.put( "Weight", 68);
              Set<String>set=map.keySet();
               for (String key:set) {
                     Integer value=map.get(key);
                     System. out.println(key +"==>>" +value);
              }
              Set<Entry<String,Integer>> entrys=map.entrySet();
               for(Entry<String,Integer> entry :entrys)
              {
                     System. out.println(entry.getKey()+entry.getValue());
                     
              }
              
       }