zoukankan      html  css  js  c++  java
  • java集合

    Map集合的两种遍历方式:Map集合无序

    public class Map1 {
    public static void main(String[] args) {
     Map<String, String> map=new HashMap();
     map.put("12", "ss");
     map.put("13", "sz");
     map.put("11", "tg");
     map.put("90", "sp");
     //遍历
     Set<String> set=map.keySet();
     for(String key:set) {
      System.out.println(key+"------------"+map.get(key));
     }
     //遍历2
     Set<Map.Entry<String, String>> set2=map.entrySet();
     for(Map.Entry<String, String> sss:set2) {
      System.out.println(sss.getKey()+"------"+sss.getValue());
     }
    }
    }

    LIst集合的增删查,有序

    public class Demo7 {
     
     public static void main(String[] args) {
      //添加元素
      ArrayList als=new ArrayList();
      Student s1=new Student("12","XZG");
      Student s2=new Student("15","fx");
      Student s3=new Student("17","ff");
      Student s4=new Student("23","oo");
      Student s5=new Student("68","yy");
      als.add(s1);
      als.add(s2);
      als.add(s3);
      als.add(s4);
      als.add(s5);
      System.out.println("元素个数:"+als.size());
      System.out.println(als.toString());
      //删除元素
      als.remove(0);
      System.out.println("元素个数"+als.size());
      //遍历元素
      Iterator it= als.iterator();
      while(it.hasNext()) {
       Student st=(Student)it.next();
       System.out.println(st.toString());
      }
      ListIterator lit=als.listIterator();
      while(lit.hasNext()) {
       Student st=(Student)lit.next();
       System.out.println(st.toString());
      }
      System.out.println(als.contains(s2));//判断此元素是否存在
      System.out.println(als.isEmpty());//判断集合是否为空
      
      
     }
    }

  • 相关阅读:
    声律启蒙(上 下卷,珍藏版)
    笠翁对韵(全卷,珍藏版附注释)
    Oracle 中 nvl、nvl2、nullif、coalesce、decode 函数的用法详解
    Groovy
    spring各版本jar包和源码
    Java 调用翻译软件实现英文文档翻译
    oracle导出序列的几种办法
    Oracle数据库内存使用情况分析查看
    window Maven私服搭建——nexus
    用户管理的备份与恢复
  • 原文地址:https://www.cnblogs.com/tilyougogannbare666/p/12986258.html
Copyright © 2011-2022 走看看