• 集合框架01


    一、集合

    1.1 Collection接口

     3 import java.util.ArrayList;
     4 import java.util.Collection;
     5 
     6 public class Demo01 {
     7     /*
     8      * ArrayList implement List
     9      * List extends Collection
    10      * Collection接口方法:
    11      *             void clear();清空集合中的所有元素,容器本身依然存在
    12      *             boolean contains(Object o);判断对象是否存在集合中
    13      *             Object[] toArray();集合中的所有元素,转换成一个数组中的元素
    14      *             remove();移除集合中指定的元素
    15      */
    16     
    17     public static void main(String[] args) {
    18         function_3();
    19     }
    20     
    21 
    22 
    23 
    24     public static void function(){
    25         Collection<String> col = new ArrayList<>();
    26         col.add("abc");
    27         col.add("bcd");
    28         System.out.println(col);
    29         
    30         col.clear();
    31         System.out.println(col);
    32     }
    33     public static void function_1(){
    34         Collection<String> col = new ArrayList<>();
    35         col.add("abc");
    36         col.add("bcd");
    37         
    38         System.out.println(col.contains("ac"));
    39     }
    40 
    41     public static void function_2() {
    42         Collection<String> col = new ArrayList<>();
    43         col.add("abc");
    44         col.add("bcd");
    45         
    46         Object[] o = col.toArray();
    47         for(int i = 0; i<o.length; i++){
    48             System.out.println(o[i]);
    49         }
    50     }
    51     public static void function_3() {
    52         Collection<String> col = new ArrayList<>();
    53         col.add("abc");
    54         col.add("bcd");
    55         col.add("dasf");
    56         System.out.println(col);
    57         
    58         if(col.remove("abc"))
    59             System.out.println("删除成功");
    60         else 
    61             System.out.println("删除失败");
    62         
    63         System.out.println(col);
    64     }
    65 }
  • 相关阅读:
    Redis在Windows上使用和集群配置
    Lzma(7-zip)和zlib
    Windump教程-参数介绍
    Windows 使用windump进行循环抓包
    wireshark长时间抓包分多个文件
    发现TCP的一种错误----客户端连接失败(10055错误号)
    MySQL [Err] 1055
    解决socket交互的10048和10055错误的总结
    Socket调用Close后如何终止套接口的问题
    linux下recv 、send阻塞、非阻塞区别和用法
  • 原文地址:https://www.cnblogs.com/Nelsoner/p/6675507.html
Copyright © 2020-2023  润新知