美文网首页js css html
Java--HashSet基本使用

Java--HashSet基本使用

作者: 李赫尔南 | 来源:发表于2022-10-27 17:15 被阅读0次

  大家在做下面练习时,重点体会“Set是无序、不可重复”的核心要点。
【示例】HashSet的使用
public class Test {
  public static void main(String[] args) {
    Set<String> s = new HashSet<String>();
    s.add("hello");
    s.add("world");
    System.out.println(s);
    s.add("hello");//相同的元素不会被加入
    System.out.println(s);
    s.add(null);
    System.out.println(s);
    s.add (null);
    System.out.println(s);
  }
}
输出:
  [world, hello]
  [world, hello]
  [null, world, hello]
  [null, world, hello]

相关文章

  • Flutter--Text/Container/Image

    Text基本使用 Container基本使用 Image基本使用

  • 基本使用

    1、 打开需要上传的文件夹执行: git init 格式化窗口 2、执行 git add . 上传文件 3、执行 ...

  • 基本使用

    href="javascript:;" 其中javascript: 是一个伪协议。它可以让我们通过一个链接来调用...

  • 基本使用

    数据库: 什么是数据库?简单来说就是存数据的。 都有什么是数据库? oracle(强大,跟金融政府打交道的,安全,...

  • 基本使用

    本文参考:https://morvanzhou.github.io/tutorials/machine-learn...

  • 6-xpath和css select基本使用

    Xpath基本使用 css select基本使用

  • MySQL语法入门(一)

    MySQL语法入门(一) 基本运算符使用 基本数学函数使用 基本字符串函数使用 基本日期时间函数使用

  • python time与datetime模块基本使用

    time模块基本使用 datetime模块基本使用

  • SQL语句基本使用

    SQL语句基本使用——增删改查 SQL语句基本使用——WHERE子句 SQL语句基本使用——AND和OR的使用 S...

  • iOS-UICollectionView基本使用

    iOS-UICollectionView基本使用 iOS-UICollectionView基本使用

网友评论

    本文标题:Java--HashSet基本使用

    本文链接:https://www.haomeiwen.com/subject/vqyttdtx.html