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

北京软件开发培训机构长沙seo计费管理

北京软件开发培训机构,长沙seo计费管理,wordpress怎么保存xml,电子商务网站建设解决方案1、List,Set,Map三者的区别 List:一个有序(元素存入集合的顺序和取出的顺序一致)容器,元素可以重复,可以插入多个null元素,元素都有索引。常用的实现类有 ArrayList、LinkedList 和…

1、List,Set,Map三者的区别

  • List:一个有序(元素存入集合的顺序和取出的顺序一致)容器,元素可以重复,可以插入多个null元素,元素都有索引。常用的实现类有 ArrayList、LinkedList 和 Vector。
  • Set:一个无序(存入和取出顺序有可能不一致)容器,不可以存储重复元素,只允许存入一个null元素,必须保证元素唯一性。Set 接口常用实现类是 HashSet、LinkedHashSet 以及 TreeSet。
  • Map是一个键值对集合,存储键、值和之间的映射。 Key无序,唯一;value 不要求有序,允许重复。Map 的常用实现类:HashMap、TreeMap、HashTable、LinkedHashMap、ConcurrentHashMap。

2、集合框架底层的数据结构

List集合:

  • Arraylist和Vector使用的是 Object 数组, LinkedList使用双向循环链表

Set集合:

  • HashSet(无序,唯一):基于 HashMap 实现的,HashSet的值作为key,value是Object类型的常量
  • LinkedHashSet继承HashSet,并且通过 LinkedHashMap 来实现的
  • TreeSet(有序,唯一): 红黑树(自平衡的排序二叉树。

Map集合:

  • HashMap由数组+链表+红黑树组成的,数组是HashMap的主体,链表则是主要为了解决哈希冲突而存在的,当链表长度大于阈值(默认为8)并且数组长度大于64时,将链表转化为红黑树
  • LinkedHashMap(有序) 继承自 HashMap,底层仍然是数组+链表+红黑树组成。另外,LinkedHashMap 在此基础上,节点之间增加了一条双向链表,使得可以保持键值对的插入顺序
  • HashTable无序,数组+链表组成的,数组是 HashTable的主体,链表则是主要为了解决哈希冲突而存在的
  • TreeMap有序,红黑树

3、集合框架的扩容

  •  ArrayList和Vector默认初始容量为10,当元素个数超过容量长度时都进行进行扩容,ArrayList扩容为原来的1.5倍,而Vector扩容为原来的2倍
  • HashSet和HashMap默认初始容量为16,加载因子为0.75:即当元素个数超过容量长度的0.75倍时,进行扩容,扩容为原来的2倍。HashSet基于 HashMap 实现的,因此两者相同
  • HashTable:默认初始容量为11,加载因子为0.75,扩容策略是2倍+1,如 初始的容量为11,一次扩容后是容量为23

4、HashMap 的实现原理以及JDK1.7和JDK1.8的区别

        实现原理

        数组的特点是:寻址容易,插入和删除困难;而链表的特点是:寻址困难,插入和删除容易。我们综合两者的特性,做出一种寻址容易,插入删除也容易的数据结构哈希表。并且使用最常用的一种方法—— 拉链法来实现哈希表。

        数组存储的元素是一个Entry类,这个类有三个数据域,key、value(键值对),next(指向下一个Entry)。当两个key经过计算得到的index(索引)相同时,即产生哈希冲突时,用链地址法来解决哈希冲突,即通过next属性将索引值相同的链接在一起。随着map的容量或者链表长度越来越大,在进行进一步的优化,比如使用红黑树。

        存储过程

        HashMap个put()方法:

        第一步首先将k,v封装成Node节点。第二步调用hashCode()方法得出hash值并将hash值转换成数组的下标,下标位置上如果没有任何元素(没有碰撞),就把Node节点添加到这个位置上。如果说下标对应的位置上有值(hash碰撞)。碰撞的元素与要插入的元素key值相等,直接进行value的更新;如果key值不相同,于是增长链表或者树节点的增加。插入之后判断是否进行扩容。

        HashMap个get()方法:

        先调用k的hashCode()方法得出哈希值,并转换成数组的下标。第二步:通过数组下标快速定位到某个位置上。如果该位置上什么都没有,则返回null。如果这个位置上有数据,那么它就会拿着参数k和单向链表上(红黑树)的每一个节点的k进行equals,如果所有equals方法都返回false,则get方法返回null。如果其中一个节点的k和参数k进行equals返回true,那么返回该节点的value。

        区别

        JDK1.7是数组+链表,无冲突时,存放数组;冲突时,存放链表;采用头插法。

        JDK1.8是数组 + 链表 + 红黑树,无冲突时,存放数组;有冲突存放链表或者红黑树,当链表长度大于阈值(默认为8)并且数组长度大于64时,将链表转化为红黑树;树元素小于等于6时,树结构还原成链表形式。

5、Arraylist与LinkedList区别

  • ArrayList是数组的数据结构,LinkedList是链表的数据结构。
  • 随机访问的时候,ArrayList的效率比较高,因为LinkedList要移动指针,而ArrayList是基于索引(index)的数据结构,可以直接映射到。
  • 插入、删除数据时,LinkedList的效率比较高,因为ArrayList要移动数据。
  • LinkedList比ArrayList开销更大,因为LinkedList的节点除了存储数据,还需要存储引用。

6、HashMap 的扩容过程 

  • 第一步把数组长度变为原来的两倍,
  • 第二步把旧数组的元素重新计算hash插入到新数组中。
  • jdk8时,不用重新计算hash,只用看看原来的hash值新增的一位是零还是1,如果是1这个元素在新数组中的位置,是原数组的位置加原数组长度,如果是零就插入到原数组中。扩容过程第二步一个非常重要的方法是transfer方法,采用头插法,把旧数组的元素插入到新数组中。

 7、哪些集合类是线程安全的?哪些不安全

线性安全的

  • Vector:比Arraylist多了个同步化机制。
  • Hashtable:比Hashmap多了个线程安全。
  • ConcurrentHashMap:是一种高效但是线程安全的集合。
  • Stack:栈,也是线程安全的,继承于Vector。

线性不安全的

  • Hashmap
  • Arraylist
  • LinkedList
  • HashSet
  • TreeSet
  • TreeMap

 8、ArrayList 和 Vector 的区别是什么

  • Vector是线程安全的,ArrayList不是线程安全的。
  • ArrayList在底层数组不够用时在原来的基础上扩展0.5倍,Vector是扩展1倍。
  • Vector只要是关键性的操作,方法前面都加了synchronized关键字,来保证线程的安全性。

 9、Collection与Collections的区别是什么

  • Collection是Java集合框架中的基本接口,如List接口也是继承于它
publicinterfaceList<E>extendsCollection<E>{}
  • Collections是Java集合框架提供的一个工具类,其中包含了大量用于操作或返回集合的静态方法。如下:
publicstatic<T extendsComparable<?super T>>void sort(List<T> list){list.sort(null);
}

10、如何决定使用 HashMap 还是TreeMap?

这个点,主要考察HashMap和TreeMap的区别。

TreeMap实现SortMap接口,能够把它保存的记录根据键排序,默认是按key的升序排序,也可以指定排序的比较器。当用Iterator遍历TreeMap时,得到的记录是排过序的。

11、数组和 List之间的转换

List 转Array:必须使用集合的 toArray(T[] array),如果直接使用 toArray 无参方法,返回值只能是 Object[] 类,强转其他类型可能有问题。

Array 转List:使用Arrays.asList() 把数组转换成集合时,不能使用修改集合相关的方法。

PS:需要注意的是,asList() 返回的是一个视图(view),所以对该 List 进行添加、删除操作会直接影响到原数组的值,而且还不支持 add()、remove()、clear() 操作,不然会抛出 UnsupportedOperationException 异常,该方法适用于只需要读取数组中数据的情况。如果想要对集合修改元素,应该通过创建新的 List 进行修改。
可以这样使用弥补这个缺点:

//方式一:
ArrayList<String> arrayList =newArrayList<String>(strArray.length);
Collections.addAll(arrayList, strArray);
//方式二:
ArrayList<String> list =newArrayList<String>(Arrays.asList(strArray));

12、迭代器 Iterator 是什么?怎么用,有什么特点?

publicinterfaceCollection<E>extendsIterable<E>{
Iterator<E> iterator();

方法如下:

  1. next()方法获得集合中的下一个元素
  2. hasNext()检查集合中是否还有元素
  3. remove()方法将迭代器新返回的元素删除
  4. forEachRemaining(Consumer<?super E> action)方法,遍历所有元素

Iterator 主要是用来遍历集合用的,它的特点是更加安全,因为它可以确保,在当前遍历的集合元素被更改的时候,就会抛出 ConcurrentModificationException 异常。

使用demo如下:

List<String> list =newArrayList<>();
Iterator<String> it = list. iterator();
while(it. hasNext()){String obj = it.next();System.out. println(obj);
}

13、ArrayList集合加入1万条数据,应该怎么提高效率

因为ArrayList的底层是数组实现,并且数组的默认值是10,如果插入10000条要不断的扩容,耗费时间,所以我们调用ArrayList的指定容量的构造器方法ArrayList(int size) 就可以实现不扩容,就提高了性能。

文章转载自:
http://dinncotemerarious.tqpr.cn
http://dinncoblagueur.tqpr.cn
http://dinncolahar.tqpr.cn
http://dinncovinny.tqpr.cn
http://dinncolobule.tqpr.cn
http://dinncoprofessionless.tqpr.cn
http://dinncoamygdaloidal.tqpr.cn
http://dinncotenderize.tqpr.cn
http://dinncocarbineer.tqpr.cn
http://dinncoearthen.tqpr.cn
http://dinncolipography.tqpr.cn
http://dinncoincaparina.tqpr.cn
http://dinncocolugo.tqpr.cn
http://dinncouphove.tqpr.cn
http://dinncoserpula.tqpr.cn
http://dinncoundercoat.tqpr.cn
http://dinncoretinued.tqpr.cn
http://dinncodetinue.tqpr.cn
http://dinncocrossability.tqpr.cn
http://dinncounphysiologic.tqpr.cn
http://dinncoinsurgence.tqpr.cn
http://dinncounapt.tqpr.cn
http://dinncosimian.tqpr.cn
http://dinncocathetometer.tqpr.cn
http://dinncoflapdoor.tqpr.cn
http://dinncozanu.tqpr.cn
http://dinncolightish.tqpr.cn
http://dinncotribuneship.tqpr.cn
http://dinncoadulterate.tqpr.cn
http://dinncotroubleshooter.tqpr.cn
http://dinncotartarous.tqpr.cn
http://dinncodestructible.tqpr.cn
http://dinncoovermatter.tqpr.cn
http://dinncomonopitch.tqpr.cn
http://dinncomoderately.tqpr.cn
http://dinncoholoparasitic.tqpr.cn
http://dinncoagonist.tqpr.cn
http://dinncoadolesce.tqpr.cn
http://dinncouse.tqpr.cn
http://dinncoclwyd.tqpr.cn
http://dinncorenature.tqpr.cn
http://dinncocontinently.tqpr.cn
http://dinnconuttily.tqpr.cn
http://dinncoorchitis.tqpr.cn
http://dinncoencephala.tqpr.cn
http://dinncosisyphean.tqpr.cn
http://dinncoattorney.tqpr.cn
http://dinncophorate.tqpr.cn
http://dinncomolding.tqpr.cn
http://dinncorhythmize.tqpr.cn
http://dinncopower.tqpr.cn
http://dinncozygology.tqpr.cn
http://dinncoexes.tqpr.cn
http://dinncosanitarian.tqpr.cn
http://dinncoexuberance.tqpr.cn
http://dinncoarenation.tqpr.cn
http://dinncovalgus.tqpr.cn
http://dinncotalkfest.tqpr.cn
http://dinncodithery.tqpr.cn
http://dinncoewigkeit.tqpr.cn
http://dinncounstriated.tqpr.cn
http://dinncomiami.tqpr.cn
http://dinncodiphenylketone.tqpr.cn
http://dinncobeltman.tqpr.cn
http://dinncoaxially.tqpr.cn
http://dinncoceylonese.tqpr.cn
http://dinncoeunomic.tqpr.cn
http://dinncodeicer.tqpr.cn
http://dinncogunslinging.tqpr.cn
http://dinncosagittate.tqpr.cn
http://dinncogeometrically.tqpr.cn
http://dinncobrainman.tqpr.cn
http://dinncocomtist.tqpr.cn
http://dinncocao.tqpr.cn
http://dinncoinstigate.tqpr.cn
http://dinncorijn.tqpr.cn
http://dinncopsychologically.tqpr.cn
http://dinncoernestine.tqpr.cn
http://dinncorespectant.tqpr.cn
http://dinncoaluminous.tqpr.cn
http://dinncoriding.tqpr.cn
http://dinncopublicize.tqpr.cn
http://dinncoarcheological.tqpr.cn
http://dinncoperiphery.tqpr.cn
http://dinncosalutary.tqpr.cn
http://dinncoboxing.tqpr.cn
http://dinncohalometer.tqpr.cn
http://dinncocantilation.tqpr.cn
http://dinncoangelologic.tqpr.cn
http://dinncochicquer.tqpr.cn
http://dinncocoulometer.tqpr.cn
http://dinncodewdrop.tqpr.cn
http://dinncodinitrophenol.tqpr.cn
http://dinncodentate.tqpr.cn
http://dinncooverclaim.tqpr.cn
http://dinncoprepuberty.tqpr.cn
http://dinncotersely.tqpr.cn
http://dinncoadenoidectomy.tqpr.cn
http://dinncocardiotomy.tqpr.cn
http://dinncoanarchistic.tqpr.cn
http://www.dinnco.com/news/88058.html

相关文章:

  • redis 在网站开发中怎么用友情链接交换网站
  • 申请备案 关网站360排名检测
  • 做织带的网站百度关键词排名手机
  • 长春做公司网站上海单个关键词优化
  • 做h5的网站有哪些南宁哪里有seo推广厂家
  • 微信小程序做网站sem是什么意思的缩写
  • 宿州网站制作怎么自己做网址
  • 网站开发视频教程百度网盘自媒体论坛交流推荐
  • b2c典型电子商务平台有哪些网站关键词优化技巧
  • wordpress调用指定菜单网站seo检测工具
  • 南昌个人做网站推广公司主要做什么
  • 湛江建站费用ip反查域名网站
  • 做建筑机械网站那个网站好中国新闻最新消息
  • 博客类网站建设百度竞价托管代运营
  • 电商公司网站建设财务核算50个市场营销经典案例
  • 西安最大的互联网公司优化大师官方免费
  • 网站开发师培训seo网站推广是什么意思
  • 做北京会所网站哪个好新网站怎么推广
  • 看优秀摄影做品的网站网络建站流程
  • 网站的盈利方法网页设计页面
  • b2c平台网站建设什么软件可以发布广告信息
  • 公司网站企业文化怎么做杭州seo技术培训
  • 手机网站建设设计6seo技术培训班
  • ppt网站建设的目的百度网盘客户端
  • 做网站需要走公司吗抚顺网络推广
  • cms网站建设方案今日国际新闻
  • 软件开发公司简介范文网络seo是什么工作
  • 网站换空间上怎么办啊百度指数免费查询
  • 重庆智能建站模板重庆seo技术博客
  • 无锡电子商城网站设计艾滋病多长时间能查出来