Collection接口和Collections集合工具类

       在学习编程的过程中,我觉得不止要获得课本的知识,更多的是通过学习技术知识提高解决问题的能力,这样我们才能走在最前方,更多Java学习,请搜索疯狂Java;

  Collection接口和Collections集合工具类详细解说

  ***容器API

  Collection接口定义了存取单个对象的方法,其子接口分别定义存储的方式和形式。

  1.List:存储的数据有顺序,可以重复。

  2.Set:存储的数据没有顺序,并且不可以重复

  3.Map接口定义了用来存储"键值对" key-value的方法

  ***Collection

  A collection represents a group of objects,known as its elements.

  Some collections allow duplicate elementsand others do not.

  Some are ordered and others unordered.

  容器类对象在调用remove,contains等方法时需要比较对象是否相等,这会涉及到对象的equals方法和hashcode方法。

  对于自己定义的类,需要重写equals和hashcode方法。

  备注:equals为true,hashCode的值也应该相等。

  通过hashCode可以找到数据在内存中存放的地址,hashCode

  方法比equals方法块,hashCode适合做索引。

  ***Collections 集合工具类

  常用方法

  1.void sort(List)

  Sorts the specified list into ascendingorder,

  according to the natural ordering of itselements.

  对List内的元素排序(LinkedList排序比较快)

  2.void shuffle(List)

  Randomly permutes the specified list usinga default source of randomness

  对List容器内的对象进行随机排列

  3.void reverse(List)www.2cto.com

  Reverses the order of the elements in thespecified list

  翻转指定列表中元素的顺序

  4.void fill(List,Object)

  Replaces all of the elements of thespecified list with the specified element.

  使用指定元素替换指定列表中的所有元素。

  5.void copy(List dest,List src)

  Copies all of the elements from one listinto another.

  将所有元素从一个列表复制到另一个列表。

  将Src List容器内容拷贝到destList 容器

  6.int binarySearch(List list,Object obj)

  Searches the specified list for thespecified object using the binary search

  algorithm.

  使二分法来搜索指定列表,以获得指定对象。

  在指定的列表中查找指定的元素

  疯狂Java培训fkjava的课程采用针对性培养,全面提升学员就业能力,重点加强训练职业素质。老师辛勤的讲解,让学员充分感受Java的魅力,充分激发每个学员对于编程的热爱,让学员在半年的时间内掌握8-10万的代码量,成为真正的技术高手,疯狂Java采用企业全真模拟开发训练,迅速积累项目经验。让学员迅速获得其他人需要花费两年才能获得的工作技能,无忧就业!

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值