zoukankan      html  css  js  c++  java
  • Set接口

    -------------siwuxie095

       

       

       

       

       

       

    Set 接口:

       

    1Set 接口中不能加入重复元素,但是可以排序

    (即 可以打断放入元素时的顺序,根据 TreeSet 排序)

       

    2Set 接口是 Collection 接口的子接口

       

    3Set 接口常用子类:HashSet(散列存放)、TreeSet(有序存放)

       

    4Set 接口在 java 包下的 util 包下

       

       

       

    代码:

       

    package com.siwuxie095.set;

       

    import java.util.HashSet;

    import java.util.Set;

    import java.util.TreeSet;

       

    public class SetDemo01 {

       

    public static void main(String[] args) {

    //声明一个Set,并初始化,注意是 泛型,指定为String

    Set<String> s1=null;

    //通过对象的多态性,通过其子类进行实例化

    s1=new HashSet<String>();//散列存放

    s1.add("A");

    s1.add("B");

    s1.add("C");

    s1.add("D");

    s1.add("1");

    s1.add("2");

    System.out.println(s1);

     

    Set<String> s2=new TreeSet<String>();//有序存放

    s2.add("C");

    s2.add("A");

    s2.add("B");

    s2.add("F");

    s2.add("D");

    s2.add("E");

    System.out.println(s2);

    }

       

    }

       

       

    运行一览:

       

       

       

       

       

    Java API 文档下载:

    下载链接1下载链接2

       

       

       

       

    【made by siwuxie095】

  • 相关阅读:
    进程与线程
    the art of seo(chapter seven)
    the art of seo(chapter six)
    the art of seo(chapter five)
    the art of seo(chapter four)
    the art of seo(chapter three)
    the art of seo(chapter two)
    the art of seo(chapter one)
    Sentinel Cluster流程分析
    Sentinel Core流程分析
  • 原文地址:https://www.cnblogs.com/siwuxie095/p/6605337.html
Copyright © 2011-2022 走看看