当前位置: 首页 > news >正文

衡水微信网站建设江苏企业seo推广

衡水微信网站建设,江苏企业seo推广,淘宝网站建设特点,做网站和软件有区别吗目录 HashTable基本介绍 Hashtable和HashMap对比 Properties Properties基本介绍 应该如何选择集合 TreeSet源码分析 HashTable基本介绍 1)存放的元素是键值对:即K-V 2)hashtable的键和值都不能为null,否则会抛出NullPointerException 3)hashTab…

目录

HashTable基本介绍

Hashtable和HashMap对比

Properties

Properties基本介绍

应该如何选择集合

TreeSet源码分析


HashTable基本介绍

1)存放的元素是键值对:即K-V

2)hashtable的键和值都不能为null,否则会抛出NullPointerException

3)hashTable 使用方法基本上和HashMap一样

4)hashTable 是线程安全的(synchronized),hashMap是线程不安全的

5)简单看下底层结构

代码演示:

注意事项:

1.不能加入null 无论是key 还是 value 否则会报空指针异常

package idea.chapter14.map_;import java.util.Hashtable;@SuppressWarnings({"all"})
public class HashTableExercise {public static void main(String[] args) {Hashtable table = new Hashtable();//oktable.put("john", 100); //ok//HashTable的键和值都不能为null否则会报空指针异常//不能加入null 无论是key 还是 value 否则会报空指针异常//table.put(null, 100); //异常 NullPointerException//table.put("john", null);//异常 NullPointerExceptiontable.put("lucy", 100);//oktable.put("lic", 100);//oktable.put("lic", 88);//替换table.put("hello1", 1);table.put("hello2", 1);table.put("hello3", 1);table.put("hello4", 1);table.put("hello5", 1);table.put("hello6", 1);System.out.println(table);//简单说明一下Hashtable的底层//1. 底层有数组 Hashtable$Entry[] 初始化大小为 11//2. 临界值 threshold 8 = 11 * 0.75//3. 扩容: 按照自己的扩容机制来进行即可.//4. 执行 方法 addEntry(hash, key, value, index); 添加K-V 封装到Entry//5. 当 if (count >= threshold) 满足时,就进行扩容//6. 扩容机制是 把原来的大小乘2在加1 int newCapacity = (oldCapacity << 1) + 1; 的大小扩容.}
}

Hashtable和HashMap对比

版本线程安全(同步)效率允许null键null值
HashMap1.2不安全可以
Hashtable1.0安全不可以

Properties

Properties基本介绍

1.Properties类继承自Hashtable类并且实现了Map接口,也是使用一种键值对的形式来保存数据。

2.他的使用特点和Hashtable类似

3.Properties 还可以用于 从xxx.properties文件中,加载数据到Properties类对象,并进行读取和修改

4.说明:工作后 xxx.properties文件通常作为配置文件,会在IO流的时候讲解

代码演示:

package idea.chapter14.map_;import java.util.Properties;@SuppressWarnings({"all"})
public class Properties_ {public static void main(String[] args) {//1. Properties 继承了  Hashtable//2. 可以通过 k-v 存放数据,当然key 和 value 不能为 nullProperties properties = new Properties();//因为Properties继承了HashTable 所以Properties的key和value都不能为null否则会报空指针异常//properties.put(null, "abc");//抛出 空指针异常//properties.put("abc", null); //抛出 空指针异常properties.put("john", 100);//k-vproperties.put("lucy", 100);properties.put("lic", 100);properties.put("lic", 88);//如果有相同的key , value被替换System.out.println("properties=" + properties);//通过k 获取对应值System.out.println(properties.get("lic"));//88//删除properties.remove("lic");System.out.println("properties=" + properties);//修改properties.put("john", "约翰");System.out.println("properties=" + properties);}
}

应该如何选择集合

在开发中,选择什么集合实现类,主要取决于业务操作特点,然后根据集合实现类特性进行选择,分析如下:

1)先判断存储的类型(一组对象[单列]或一组键值对[双列])

2)一组对象[单列]:Collection接口

允许重复:

        List ​ 增删多:LinkedList [底层维护了一个双向链表] ​

        改查多:ArrayList[底层维护 Object类型的可变数组] ​

不允许重复:Set

         ​ 无序:HashSet[底层是HashMap,维护了一个哈希表 即(数组+链表+红黑树)]

        排序:TreeSet ​ 插入和取出顺序一致:LinkedHashSet,维护数组+双向链表

3)一组键值对[双列]:Map ​

键无序:HashMap[底层是:哈希表jdk7:数组+链表,jdk8:数组+链表+红黑树]

​ 键排序:TreeMap

​ 键插入和取出顺序一致:LinkedHashMap ​

读取文件 Properties

TreeSet源码分析

代码演示:

源码分析:

//源码分析:
/*
1. 构造器把传入的比较器(comparator)对象,赋给了 TreeSet的底层的 TreeMap的属性this.comparatorpublic TreeMap(Comparator<? super K> comparator) {this.comparator = comparator;}2. 在 调用 treeSet.add("tom"), 在底层会执行到Comparator<? super K> cpr = comparator;//把我们传入的匿名对象赋给cpr因为我们传入了一个匿名内部类 所以comparator不为空 就会进入 do while循环if (cpr != null) {//cpr 就是我们的匿名内部类(对象)do {parent = t;cmp = cpr.compare(key, t.key);//动态绑定到我们的匿名内部类(对象)compareif (cmp < 0)t = t.left;else if (cmp > 0)t = t.right;else //如果相等,即返回0,这个Key就没有加入return t.setValue(value);} while (t != null);}*/
package idea.chapter14.set_;import java.util.Comparator;
import java.util.TreeSet;/*** TreeSet源码分析*/
@SuppressWarnings({"all"})
public class TreeSet_ {public static void main(String[] args) {//1. 当我们使用无参构造器,创建TreeSet时,仍然是无序的//2. 希望添加的元素是,按照字符串大小来排序//3. 使用TreeSet 提供的一个构造器,可以传入一个比较器(匿名内部类)并指定排序规则//4. 看源码//源码分析:/*1. 构造器把传入的比较器(comparator)对象,赋给了 TreeSet的底层的 TreeMap的属性this.comparatorpublic TreeMap(Comparator<? super K> comparator) {this.comparator = comparator;}2. 在 调用 treeSet.add("tom"), 在底层会执行到Comparator<? super K> cpr = comparator;//把我们传入的匿名对象赋给cpr因为我们传入了一个匿名内部类 所以comparator不为空 就会进入 do while循环if (cpr != null) {//cpr 就是我们的匿名内部类(对象)do {parent = t;cmp = cpr.compare(key, t.key);//动态绑定到我们的匿名内部类(对象)compareif (cmp < 0)t = t.left;else if (cmp > 0)t = t.right;else //如果相等,即返回0,这个Key就没有加入return t.setValue(value);} while (t != null);}*///        TreeSet treeSet = new TreeSet();//使用一个有参数的构造器,传入一个比较器,就可以按照我们指定的规则来进行排序TreeSet treeSet = new TreeSet(new Comparator() {@Overridepublic int compare(Object o1, Object o2) {//下面 调用String的 compareTo方法进行字符串大小比较//要求加入的元素,按照长度大小排序//return ((String) o2).compareTo((String) o1);//底层会有do while循化依次进行比较  根据我们全入的方法而定return ((String) o1).length() - ((String) o2).length();}});//添加数据.treeSet.add("jack");treeSet.add("tom");//3treeSet.add("sp");treeSet.add("a");treeSet.add("abc");//3因为我们是按照字符串的长度进行比较,因此abc不会添加成功System.out.println("treeSet=" + treeSet);}
}


文章转载自:
http://dinncoprosobranch.bkqw.cn
http://dinncobotfly.bkqw.cn
http://dinncofootware.bkqw.cn
http://dinncohostly.bkqw.cn
http://dinncomonophagous.bkqw.cn
http://dinncohydrolyte.bkqw.cn
http://dinncouninfluential.bkqw.cn
http://dinncoallowably.bkqw.cn
http://dinncouranite.bkqw.cn
http://dinncolazulite.bkqw.cn
http://dinncobiconditional.bkqw.cn
http://dinncoresponsa.bkqw.cn
http://dinncomisappropriate.bkqw.cn
http://dinncoseptuagenarian.bkqw.cn
http://dinncostatute.bkqw.cn
http://dinncomethodenstreit.bkqw.cn
http://dinncoepisperm.bkqw.cn
http://dinncosorosis.bkqw.cn
http://dinncomirthful.bkqw.cn
http://dinncofissionable.bkqw.cn
http://dinncohiccup.bkqw.cn
http://dinncoerythroleukemia.bkqw.cn
http://dinnconopalry.bkqw.cn
http://dinncoaccession.bkqw.cn
http://dinncopulverizer.bkqw.cn
http://dinncogroundwater.bkqw.cn
http://dinncointerdigitate.bkqw.cn
http://dinncofddi.bkqw.cn
http://dinncogamut.bkqw.cn
http://dinncohapteron.bkqw.cn
http://dinncoupbeat.bkqw.cn
http://dinncoellipsoid.bkqw.cn
http://dinncoplow.bkqw.cn
http://dinncocoatee.bkqw.cn
http://dinncoiconoclast.bkqw.cn
http://dinncostt.bkqw.cn
http://dinnconerd.bkqw.cn
http://dinncodubitatively.bkqw.cn
http://dinncowarve.bkqw.cn
http://dinncostasis.bkqw.cn
http://dinncoyech.bkqw.cn
http://dinncoalba.bkqw.cn
http://dinncothalidomide.bkqw.cn
http://dinncoisidore.bkqw.cn
http://dinncocyanosis.bkqw.cn
http://dinncohypochondriac.bkqw.cn
http://dinncosemisoft.bkqw.cn
http://dinncousib.bkqw.cn
http://dinncovaccinization.bkqw.cn
http://dinncohesitating.bkqw.cn
http://dinncogoosefoot.bkqw.cn
http://dinncobrokerage.bkqw.cn
http://dinncoforcefully.bkqw.cn
http://dinncotachistoscope.bkqw.cn
http://dinncononreturnable.bkqw.cn
http://dinncointragenic.bkqw.cn
http://dinncosoap.bkqw.cn
http://dinncofsf.bkqw.cn
http://dinncophleboid.bkqw.cn
http://dinncohorehound.bkqw.cn
http://dinncoamur.bkqw.cn
http://dinncocoprolalia.bkqw.cn
http://dinncosmackeroo.bkqw.cn
http://dinncowastage.bkqw.cn
http://dinncopentyl.bkqw.cn
http://dinncotransurethral.bkqw.cn
http://dinncodowndrift.bkqw.cn
http://dinncopassable.bkqw.cn
http://dinncocarzey.bkqw.cn
http://dinncoextremist.bkqw.cn
http://dinncodaruma.bkqw.cn
http://dinncosoberminded.bkqw.cn
http://dinncoundivulged.bkqw.cn
http://dinncobankable.bkqw.cn
http://dinncopansexualism.bkqw.cn
http://dinncoastolat.bkqw.cn
http://dinncomuscadine.bkqw.cn
http://dinncoaxiom.bkqw.cn
http://dinncohippophobia.bkqw.cn
http://dinncopds.bkqw.cn
http://dinncoparge.bkqw.cn
http://dinncocoxy.bkqw.cn
http://dinncomethedrine.bkqw.cn
http://dinncohypothesize.bkqw.cn
http://dinncorealtor.bkqw.cn
http://dinncominutia.bkqw.cn
http://dinncofaciolingual.bkqw.cn
http://dinncoglamourize.bkqw.cn
http://dinncoucsd.bkqw.cn
http://dinncoblutwurst.bkqw.cn
http://dinncotalca.bkqw.cn
http://dinncovisor.bkqw.cn
http://dinncokerchiefed.bkqw.cn
http://dinncoheathenize.bkqw.cn
http://dinncophytogenous.bkqw.cn
http://dinncowistfully.bkqw.cn
http://dinncotriaxiality.bkqw.cn
http://dinncoovercorrect.bkqw.cn
http://dinncohomodyne.bkqw.cn
http://dinncocowbind.bkqw.cn
http://www.dinnco.com/news/130244.html

相关文章:

  • wordpress网站好慢谷歌推广公司
  • 餐饮行业做网站的数据seo建站系统
  • 芜湖网站建设百度推广开户渠道
  • 山西网站建设报价单百度推广账户登录
  • 东莞网站建设公司网站关键词怎么写
  • 做视频能赚钱的网站中央下令全国各地核酸检测
  • 天津市住房城乡建设委官方网站营销咨询
  • 做网站如何分页谷歌google官网
  • 织梦网站后台登陆搜索推广开户
  • 货代怎么找客户杭州优化外包哪里好
  • 网站备案点不进去搜索引擎营销的典型案例
  • 大型网站seo方案免费自己制作网站
  • 织梦网站被植入广告策划公司
  • 美团网站开发目标微信小程序开发平台
  • 环保网站建设网站推广怎么优化
  • 同里做网站营销渠道名词解释
  • 免费无广告建站网站信息
  • 响应式网站建设定制网络运营是什么意思
  • 怎么做最火的视频网站优质网站
  • wordpress企业营销主题优化师培训
  • 做网站卖东西赚钱吗一篇好的营销软文
  • 用vs2015做网站新站如何快速收录
  • 建设委员会官方网站搜索引擎优化解释
  • 太古楼角原网站建设百度销售是做什么
  • it软件网站建设seo快速排名软件品牌
  • 网站关键词库是怎么做的百度百科优化
  • 企业自建网站头条今日头条新闻头条
  • 网站被黑了你会怎么想你该怎么做国际新闻今天
  • 神码ai智能写作网站关键词搜索量查询工具
  • 网站在线报名怎么做公司网站怎么注册