黑马程序员-Java之HashSet

使用模拟工具Modbus poll 和PLC 通讯 使用模拟工具Modbus poll 和PLC 通讯 简介 Modbus Poll 是一个模拟Modbus 主站的工具。不用在现场调试,在家也能使用,方便快捷的调试验证程序。使用它可以和PLC进行Modbus TCP /RTU 通讯等功能,接下来为大家介绍使用Modbus Poll 和 PLC 进行 Modbus TCP 通讯。 组态PLC PLC作为我们的从站和Modbus Poll 通讯,那我们组态一个PLC。 创建通信DB 创建一个DB块,在数据类型处输入:TCON_IP_V4 阅读详情

--------------android培训、java培训、期待与您交流!---------------------


特性:元素存放无序,且元素值唯一
原理:由于底层元素存放结构是哈希表结构,所以是无序的,当新的元素存放的时候,会调用该元素的hashCode()计算出一个哈希值,然后去和集合中的原有元素的哈希值比较,如果相同,则调用元素的equals()进行内容的比较,内容不同则会在同一哈希值下按顺序依次排列存储,如果内容也相同则不会存储,以保证元素的唯一性
实例:往HashSet中存入自定义对象
代码:
package com.itheima;

import java.util.HashSet;
import java.util.Iterator;

class Person {
    private String name;
    private int age;
    public Person(String name,int age){
        this.setName(name);
        this.setAge(age);
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public int hashCode(){
        int hCode = name.hashCode()+age*39;
        System.out.println(this.name+"---hashCode---"+hCode);
        return hCode;
    }
    public boolean equals(Object obj){
        if(!(obj instanceof Person)){
            return false;
        }
        Person p = (Person)obj;
        System.out.println(this.name+"---equals---"+p.name);
        return this.name.equals(p.name) && this.age==p.age;
    }
    
}
public class HashSetDemo {
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        HashSet hs = new HashSet();//创建一个HashSet对象
        hs.add(new Person("zhangshan",18));//添加元素(存储)
        hs.add(new Person("lisi",20));
        hs.add(new Person("wangwu",19));
        hs.add(new Person("zhaoliu",18));
        hs.add(new Person("lisi",20));
        System.out.println("------------------------");
        Iterator it = hs.iterator();
        while(it.hasNext()){//循环打印元素
            Person p = (Person)it.next();
            System.out.println(p.getName()+"----"+p.getAge());
        }
    }

}


置顶必读(2) |《YOLOv8实战:从入门到深度优化》总目录导航 & 学习路线指南(持续更新中) 🏆 本文收录于 《YOLOv8实战:从入门到深度优化》 专栏。该专栏系统复现并梳理全网各类 YOLOv8 改进与实战案例(当前已覆盖分类 / 检测 / 分割 / 追踪 / 关键点 / OBB 检测等方向),坚持持续更新 + 深度解析,质量分长期稳定在 97 分以上,可视为当前市面上 覆盖较全、更新较快、实战导向极强 的 YOLO 改进系列内容之一。 阅读详情

相关推荐

用ST25DV芯片+KiCad快速设计NFC标签天线:参数计算/脚本生成/实测优化全流程

本文详细介绍了使用ST25DV芯片和KiCad工具设计NFC标签天线的全流程,包括参数计算、脚本生成和实测优化。通过解析芯片等效工作原理和设计思路,帮助开发者避开常见陷阱,实现高效、可量产的天线设计。文章还提供了Python计算工具和KiCad自动化脚本,大幅提升设计效率和成功率。

jj890的博客 757

Java中如何向一个HashSet对象中添加元素呢?

Java中向一个HashSet对象中添加元素的方法分享

qq_25073223的博客 1041

【技术解析】LUT-Fuse:如何通过可学习查找表与蒸馏技术,为边缘设备解锁实时图像融合

本文解析了ICCV 2025提出的LUT-Fuse技术,它通过可学习查找表与知识蒸馏,解决了边缘设备上图像融合的质量、速度与功耗“不可能三角”。该方法将复杂计算预编译为高速查找表,在Jetson等设备上实现100+ FPS的实时红外-可见光图像融合,为无人机、安防等应用提供了高效解决方案。

code8的博客 495

详述HashSet类add方法(一)

1.HashSet对象的创建 创建HashSet对象: package com.jd.add; import java.util.HashSet; public class Test1 { public static void main(String[] args) { HashSet<String> names = new HashSet<String>(); ...

bravery__的博客 649

利用GPAC生成MP4文件

GPAC主要针对学生和内容创作者,代表了一个跨平台的多媒体框架,开发人员可以使用它在 LGPL 许可下制作开源媒体。GPAC多媒体框架兼容范围广泛的流行文件类型,从常见格式(如 AVI、MPEG 和 MOV)到复杂格式(如 MPEG-4 系统或 VRML/X3D)和 360 电影。

深之JohnChen的专栏 1770

赛灵思Xilinx 7系列FPGA硬件设计知识总结

本文讲述了赛灵思7系列FPGA硬件设计的关键点,为使用该系列FPGA提供硬件设计参考。

csdn_dsw的博客 3618

HashSet中add()方法的使用

HashSet 传入对象,怎么过滤 首先,我们知道所有的Set里面都套了一个Map,使用Map的Key存值,Value存放一个固定的Object,这是适配器模式。源码如下: public class HashSet<E> extends AbstractSet<E> implements Set<E>, Cloneable, java.io.Serializable { static final long serialVersionUID =

Dream It Possible 5217

说说PSTN、ISDN、 ADSL三种互联网接入方式的区别。

互联网的接入方式: 电话拨号接入(PSTN) ISDN接入 ADSL接入 Cable MODEM接入 局域网接入 光纤接入(FDDI) 卫星接入 DDN专线 目前来说,ADSL和Cable MODEM比较常用,今天我们就先来说说PSTN、ISDN和ADSL的区别。 电话拨号接入(PSTN/POTS,Public Switched Telephone Network / Public Oold Telephone Service) 数据终端设备(DTE)通过数据通信设备(DCE)再连

Winyaz的博客 2万+

【Java学习笔记】HashSet实现对自定义对象无重复添加

我们都知道,HashSet的特点就是无索引,不重复,无序(存取不一致),然而在用HashSet对自定义对象进行操作时,会出现种种问题导致相同的对象也能添加进HashSet中,这篇博客就解决了这个问题。 我们先自定义一个Person类 public class Person { private String name; private int age; public Person() { ...

weixin_44718349的博客 412

Mac电脑用Latex论文排版3天速成5天实战de笔记

我后悔了,这五天竞赛搞得我视力都下降了...一个冲动的决定后成为数模竞赛论文写手,3天速成+5天时间=点亮攻克latex写论文技能💡关于Overleaf我是Mac,曾经按照大部分推荐的方式用TEXshop+vs code,但是把模板导入就开始报错。跟着少之又少的适配mac的教程(此时我已知道大概是走错路了)改了配置也无效。海鲜市场找佬改了半天,佬问我:一定要用VC吗?我说,那倒也不是。于是佬推荐我overleaf,三下五除二帮我挑配了环境,美汁汁收了我30块钱。

luwanjoyce的博客 2247

【Python_Zebra斑马打印机编程学习笔记(二)】基于BarTender将btw文件转换为zpl文件

本文介绍如何基于 BarTender 软件将 btw 格式的文件转换为 zpl 格式的文件,有需要的读者可以点赞收藏,也欢迎在评论区进行讨论。

禾戊之昂的博客 3375

Java集合类实验集

1、题目一:List简单操作 1.1 问题描述 List接口的特有方法:1)编写一个类Example01;2)在类中定义两个List集合,并向其中一个集合中添加数据;3)用subList(int fromIndex, int toIndex)方法获取集合的一部分;4)用set(int index, E element)方法修改一个元素;5)用add(int index, E element)方法增加一个元素。 1.2解题思路 需要运用到List集合的常用方法 void add(int inde.

m0_48936146的博客 3476

Xilinx FPGA平台GTX简易使用教程(汇总篇)

Xilinx平台GTX简易使用教程,先“知其然”,慢慢再研究“所以然”。

数字IC/FPGA杂货铺,找一找,或许有你想要的~ 3万+

黑马程序员——java集合中的HashSet

黑马程序员——java集合中的HashSet和TreeSet     ---------------------- ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ---------------------- 1.        java集合框架中的Set接口: Java的集合类主要由两个接口派生而出:Collection和Map. Collectio

xyyancsd的专栏 558

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

黑马程序员_java基础hashSet

------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! ------- /*hashSet通过hashCode和equals两个方法来保证元素的唯一性*/ /*往hashSet集合中存入自定义对象,姓名和年龄相同的为同意个人*/ class HashSetDemo { public static void sop(Object obj) { S

saghir的专栏 396

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

黑马程序员----java基础HashSet和TreeSet总结

------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! ------- 黑马程序员----java基础HashSet和TreeSet总结   课堂总结: 1. 可变参数   1.1 参数类型一样,个数不确定,使用可变参数   1.2 格式  类型...变量名,就是数组   1.3 注意事项     |-- 只能写一个可变参数     |

DreamStartDemo的博客 534

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

黑马程序员——Java中HashSet中hashCode()的原理

一直以来,只知道如果用HashSet或HashTree存储一个自定义类型对象,那么该类中一定要重写hashCode()、equas()两个方法,但具体原因今天看了张孝祥老师的视频才知道,豁然开朗啊!而且我感觉老师讲出了hashcode的来源。

taooattao的专栏 535

黑马程序员:Java基础——Set集合之HashSet

------- Java EE培训、java培训、期待与您交流! ----------

JAVA程旭元的专栏 453

黑马程序员-Java基础之Set接口及HashSet类

================ ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ================ 前面已经介绍过Set集合,它类似与一个罐子,一旦把对象“丢进”Set集合中,集合里多个对象之间没有明显的顺序。Set集合和Collection基本上完全一样,没有提供任何额外的方法。实际上Set就是Collection,只是行为不同(Set不允许包含重复元...

weixin_30488313的博客 86

黑马程序员—Java集合框架(Set、HashSet、TreeSet)

------- android培训、java培训、期待与您交流! ----------      * Set子接口:元素是无序的(存入和取出的顺序不一定一致),元素是不可以重复的。  *   |--HashSet:底层数据结构是哈希表。HashSet是如何保证元素的唯一性呢?  *   |   是通过元素的两个方法,hashCode和equals来完成。如果两个元素的hashCode

welcome to my blog,thank you! 682

黑马程序员-Java中的hashCode()方法和hashSet集合

---------------------- ASP.Net+Unity开发、.Net培训、期待与您交流! ---------------------- 先来节诶少

luili16的专栏 652

黑马程序员_JAVA笔记14——集合框架(List、HashSet、TreeSet)

------- android培训、java培训、期待与您交流! ---------- 1、为什么出现集合类,面向对象语言对事物的体现都是以对象的形式,所以为了方便对多个对象的操作,就对对象进行存储,集合就是存储对象最长哟昂的一种方式。         数组与集合类都是容器,有何不同?数组虽然也可以存储对象,但长度是固定的,集合长度是可变的。数组中可以存储基本数据类型,集合只能存储对象。数组只

u011453546的专栏 773

黑马程序员--java三种集合中的HashMap,HashSet和ArrayList的总结

java三种集合中的HashMap和HashSet以及ArrayList的总结

265

黑马程序员----------java基础加强之hashSet总结

----------------------android培训、java培训、期待与您交流! ----------------------     关于Set接口下的hashSet总结。  HashSet的使用一直是令人纠结的问题,所以今天翻了笔记把它总结一下,希望能够给看到的人们提供帮助。 他是java.util包下的,使用他们时一般要重新覆盖hashCode()和equa

zixue793938813的专栏 465

黑马程序员_Java第14天知识总结_集合类(集合框架)_Collection_迭代器_List_Set_HashSet

------- android培训、java培训、期待与您交流! ---------- 今天学习的知识点: 集合类(集合框架)_Collection_迭代器_List_ArrayList_LinkedList_枚举_Set_HashSet_集合中是怎样判断元素唯一性_模拟堆栈 复习String StringBuilder 基本数据类型对象包装类的练习题 为什么出现集合类?

v191211的专栏 1092

黑马程序员---2015.6.21.java基础笔记---TreeSet---HashSet---HashMap

------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! ------- 1.TreeSet:可以对set集合中的元素进行排序,没有重复元素且有序!                     自定义对象,必须实现Comparable接口,重写compareTo(T o) 方法                     底层数据结构是二叉树。          

u010870544的博客 452
上一篇: 黑马程序员-Java之LinkedList
下一篇: 黑马程序员-java之TreeSet,Comparable,Comparator
forTomorrow_java
博客等级 码龄11年 0粉丝 14原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值