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

    arraylist

    package com.zit;
    
    import java.util.ArrayList;
    
    public class Listdemo {
        public static void main(String[] args) {
            var list = new ArrayList<String>();
            list.add("java");
            list.add("mysql");
            list.add("css");
            list.add(".net");
            list.add("sql-sever");
            list.add("ori_cal");
    //      list.clear();
    //        list.remove("java");
    //       list.remove(3);
            list.indexOf("java");
            list.size();
    
            for (String str : list) {
                System.out.print(str + " ");
            }
            list.forEach(System.out::println);
            System.out.println("------------------------------");
    
            list.stream().sorted().forEach(System.out::println);
            System.out.println("------------------------------");
            /* for (String str : list) {
                if (str.contains("s")) {
                    System.out.println(str);
                }
            }*/
            list.stream().filter(e->e.contains("s")).forEach(System.out::println);
            System.out.println("-----------------------");
            list.forEach(e->{
                if(e.contains("s")) {
                    System.out.println(e);
                }
            });
    
        }
    }

    hashset

    public class Setdemo {
        public static void main(String[] args) {
            var list = new HashSet<String>();
            list.add("java");
            list.add("mysql");
            list.add("css");
            list.add(".net");
            list.add("sql-sever");
            list.add("ori_cal");
            //list.remove("java");
            //list.clear();
            //list.isEmpty();
            System.out.println(list);
            list.stream().sorted().forEach(System.out::println);
            list.stream().filter(e -> e.contains("s")).forEach(System.out::println);
        }

    hashmap

    public static void main(String[] args) {
            HashMap<String, String> list = new HashMap();
            list.put("ha", "河南");
            list.put("hn", "湖南");
            list.put("bj", "北京");
            list.put("sh", "上海");
            //list.clear();
            //list.remove("ha");
            list.isEmpty();
            list.containsKey("ha");
            list.containsValue("河南");
            list.keySet();//键集合
            list.values();//值集合
            list.size();
            list.forEach((key, value) -> {
                System.out.println(key);
                System.out.println(list.get(key));
                System.out.printf("list['%s']=%s
    ",key,value);
            });
            for (String s : list.keySet()) {
                System.out.println(s);
                System.out.println(list.get(s));
            }
            list.keySet().forEach(e -> {
                System.out.println(e);
                System.out.println(list.get(e));
            });
            list.keySet().forEach(System.out::println);
        }

    properties

    public static void main (String[] args) throws IOException {
            Properties p = new Properties();
            p.put("db","mydb");
            p.put("user","root");
            p.put("password","root");
            p.put("time","now");
            System.out.println(p.size());
            System.out.println(p.get("password"));
            System.out.println(p.getProperty("password"));
            p.keySet();
            p.values();
            p.store(new FileWriter("c:/my.properties"),"");
            System.out.println("-----------------------------");
            //读取my.peoperties中的内容
            p.load(new FileReader("c:/my.properties"));
            p.forEach((key,value)-> {
                System.out.println(key);
                System.out.println(value);
            });
        }
  • 相关阅读:
    设计模式学习总结
    算法时间复杂度和空间复杂度表示
    SQLite简单使用
    接口,组合和继承的想法
    二叉树的学习
    Oracle 常用命令大汇总
    Oracle 最常用功能函数经典汇总
    oracle 常用command
    历史最牛演讲:Oracle总裁Yale演讲全文中英文对照
    深入abstract class和interface
  • 原文地址:https://www.cnblogs.com/zxwen/p/9675842.html
Copyright © 2011-2022 走看看