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

电影网站权重怎么做如何做关键词优化

电影网站权重怎么做,如何做关键词优化,深圳商城软件开发,顺德网页定制目录 目录 目录 11.1 Collection集合 11.1.1 集合的概念 11.1.2 Collection接口 1、添加元素 2、删除元素 3、查询与获取元素 11.2 List 有序集合 11.2.1 新增方法 11.2.2 ArrayList 11.2.3 LinkedList 1、单向链表 2、双向链表 3、删除元素 11.3 Set 无序集合 …

目录

目录

目录

11.1 Collection集合

11.1.1 集合的概念

11.1.2 Collection接口

1、添加元素

2、删除元素

3、查询与获取元素

11.2 List 有序集合

11.2.1 新增方法

11.2.2 ArrayList

11.2.3 LinkedList

1、单向链表

2、双向链表

3、删除元素

11.3 Set 无序集合

11.3.1 HashSet

1、HashSet 的特点

11.3.2 TreeSet

11.5 Collections工具类



11.1 Collection集合

11.1.1 集合的概念

集合是java中提供的一种容器,可以用来存储多个数据。

集合和数组既然都是容器,它们有啥区别呢?

数组的长度是固定的,集合的长度是可变的。

数组中可以存储基本数据类型值,也可以存储对象,而集合中只能存储对象 。

集合主要分为两大系列:CollectionMap,Collection 表示一组对象,Map表示一组映射关系或键值对。

11.1.2 Collection接口

Collection 层次结构中的根接口。 Collection 表示一组对象,这些对象也称为 collection 的元素。一些 collection 允许有重复的元素,而另一些则不允许。一些 collection 是有序的,而另一些则是无序的。JDK 不提供此接口的任何直接实现:它提供更具体的子接口(如 Set无序集合 和 List有序集合、Queue队列)实现。此接口通常用来传递 collection,并在需要最大普遍性的地方操作这些 collection。

Collection<E>是所有单列集合的父接口,因此在Collection中定义了单列集合(List和Set)通用的一些方法,这些方法可用于操作所有的单列集合。方法如下:

1、添加元素

(1)add(E obj):添加元素对象到当前集合中

(2)addAll(Collection<? extends E> other):添加other集合中的所有元素对象到当前集合中,即this = this ∪ other

  @Testpublic void test01(){
//        添加元素
// (1)add(E obj):添加元素对象到当前集合中Collection<Integer> number = new ArrayList<>();number.add(10);System.out.println(number);
//        (2)addAll(Collection<? extends E> other):
//        添加other集合中的所有元素对象到当前集合中,
//        即this = this ∪ otherCollection<Integer> number1 =new ArrayList<>();number1.add(10);number1.add(20);number1.add(30);number1.addAll(number);System.out.println(number1);}

2、删除元素

(1) boolean remove(Object obj) :从当前集合中删除第一个找到的与obj对象equals返回true的元素。

@Testpublic void test02(){
//        (1) boolean remove(Object obj) :
//        从当前集合中删除第一个找到的与obj对象equals返回true的元素。List<String> list = new ArrayList<>();list.add("yang");list.add("asdlfj");list.add("qweoqiwue");list.remove("yang");System.out.println(list);}

  (2)boolean removeAll(Collection<?> coll):从当前集合中删除所有与coll集合中相同的元素。即this = this - this ∩ coll

 @Testpublic void test03(){/* (2)boolean removeAll(Collection<?> coll):从当前集合中删除所有与coll集合中相同的元素。即this = this - this ∩ coll*/Collection<String> str =new ArrayList<>();str.add("zhangsan");str.add("zhangsan");str.add("王五");str.add("李四");str.add("zhangsan");str.add("赵六");str.add("猪猪侠");System.out.println(str);Collection<String> str1 = new ArrayList<>();str1.add("zhangsan");System.out.println(str1);str.removeAll(str1);System.out.println(str);}

(3)boolean removeIf(Predicate<? super E> filter) :删除满足给定条件的此集合的所有元素。

 @Testpublic void test04() {/** (3)boolean removeIf(Predicate<? super E> filter) :* 删除满足给定条件的此集合的所有元素。* */Collection<String> list = new ArrayList<>();list.add("张三");list.add("张a");list.add("张三");list.add("张三");list.add("张三");Collection<String> list1 = new ArrayList<>();list1.add("张三");list1.add("张a");list1.add("张三");list1.add("张三");list1.add("张三");list.addAll(list1);//把list1添加到list里面list.removeIf(new Predicate<String>() {@Overridepublic boolean test(String s) {return s.contains("张a");}});list.removeIf(new Predicate<String>() {@Overridepublic boolean test(String s) {return false;}});System.out.println(list);}

(4)boolean retainAll(Collection<?> coll):从当前集合中删除两个集合中不同的元素,使得当前集合仅保留与c集合中的元素相同的元素,即当前集合中仅保留两个集合的交集,即this = this ∩ coll;

@Testpublic void test05(){/** (4)boolean retainAll(Collection<?> coll):* 从当前集合中删除两个集合中不同的元素,* 使得当前集合仅保留与c集合中的元素相同的元素,* 即当前集合中仅保留两个集合的交集,即this  = this ∩ coll;* */Collection<String> str = new ArrayList<>();str.add("张三");str.add("王五");str.add("李四");str.add("asd四");str.add("a四");str.add("asd四");System.out.println(str);Collection<String> str1 = new ArrayList<>();str1.add("张三1");str1.add("王五2");str1.add("李四");str1.add("asd四");str1.add("a四");str1.add("asd四");System.out.println(str1);str.retainAll(str1);System.out.println("取交集后:"+str);str1.retainAll(str);System.out.println("取交集后:"+str1);}
3、查询与获取元素

(1)boolean isEmpty():判断当前集合是否为空集合。

  @Testpublic void test06() {
//            (1)boolean isEmpty():判断当前集合是否为空集合。Collection<String> str =new ArrayList<>();str.add("asdf");System.out.println(str.isEmpty());}

(2)boolean contains(Object obj):判断当前集合中是否存在一个与obj对象equals返回true的元素。

 @Testpublic void test07(){
//        (2)boolean contains(Object obj):
//        判断当前集合中是否存在一个与obj对象equals返回true的元素。Collection<String> str= new ArrayList<>();str.add("啊撒旦解放");str.add("啊撒旦");str.add("啊解放");}

(3)boolean containsAll(Collection<?> c):判断c集合中的元素是否在当前集合中都存在。即c集合是否是当前集合的“子集”。

 @Testpublic void test08(){
//        (3)boolean containsAll(Collection<?> c):
//        判断c集合中的元素是否在当前集合中都存在。
//        即c集合是否是当前集合的“子集”。Collection<String> str = new ArrayList<>();str.add("asdfasg");str.add("dfasg");str.add("afasg");str.add("asdsg");str.add("aasg");str.add("fasg");Collection<String> str1= new ArrayList<>();str1.add("aesfas");System.out.println(str.containsAll(str1));}

(4)int size():获取当前集合中实际存储的元素个数

(5)Object[] toArray():返回包含当前集合中所有元素的数组

 @Testpublic void test09(){/*** (4)int size():获取当前集合中实际存储的元素个数*/Collection<String> str = new ArrayList<>();str.add("sajf");str.add("sajf");str.add("sajf");str.add("sajf");System.out.println(str.size());
//        (5)Object[] toArray():
//        返回包含当前集合中所有元素的数组Collection<String> list = new ArrayList<>();list.add("asdljkflaks");list.add("asdljkflaks");list.add("sdaf");list.add("sdaf");list.add("sdaf");list.add("sdaf");System.out.println(list.toArray());/*[Ljava.lang.Object;@6ee52dcd*/Object[] array =list.toArray();
//        iter//快捷键
//      itar//for (Object o : array) {System.out.println(o);}}

11.2 List 有序集合

List集合代表一个元素有序、可重复的集合。集合中每个元素都有对应的顺序索引。

11.2.1 新增方法

作为Collection子接口,自然可以使用父接口的所有方法,当然也有新增的方法

方法名说明
add(E e)增加单个数据
addAll(Collection<? extends E> c)将一个 Collection 集合的数据添加到现在的集合中
remove(Object o)删除指定的元素
contains(Object o)判断集合是否包含指定的元素
size()得到集合的数据总数
isEmpty()判断集合是否有数据
get(int index)通过索引获取对应的数据元素
set(int index, E element)通过索引和新的元素替换原有内容
toArray()将List转为对象数组

11.2.2 ArrayList

ArrayList 是List 接口的大小可变数组的实现。实现了所有可选列表操作, 并允许包括null 在内的所有元素。除了实现List 接口外, 此类还提供一些方法来操作内部用来存储列表的数组的大小( 此类大致上等同于 vector 类, 但 vector 是同步的) 。

ArrayList 底层使用数组实现,特点就和数组一致:查询速度快,增删速度慢。

11.2.3 LinkedList

LinkedList 和ArrayList不同,是一个链表结构。可当作堆栈、队列、双端队列 。链表是一种在物理上非连续、非顺序的数据结构,由若干节点(node)所组成。链表有单链表和双链表之分。

1、单向链表

单向链表的每一个节点包含两部分,一部分是存放数据的变量data,另一部分是指向下一个节点的指针next。正如地下党的联络方式,一级一级,单线传递 。

2、双向链表

双向链表比单向链表稍微复杂一些,它的每一个节点除了拥有data和next指针,还拥有指向前置节点的 prev 指针

3、删除元素

11.3 Set 无序集合

Set 集合就像是一个罐子,将数据丢进来就行,因为是丢进来的,Set集合通常不会记忆元素的添加顺序(无序)。 Set接口的方法和Collection基本相同,但Set不允许包含重复的元素。

11.3.1 HashSet

HashSet是Set接口的典型实现,大多时候使用Set集合的时候都是使用这个实现类。因为使用Hash算法来储存元素,因此有很好的存储于查找性能。

1、HashSet 的特点

不能保证元素的排列顺序, 顺序可能与添加顺序不同, 顺序也有可能发生变化 HashSet 不是同步的, 如果多个线程同时访问一个HashSet , 假设有两个或者两个以上线程同时修改了HashSet 集合时, 则必须通过代码来保证其同步 集合元素值可以是null 。

当向HashSet 集合中存入一个元素时,会调用该对象的hashCode() 方法来得到该对象的hashCode 值,然后根据该hashCode 值决定该对象在HashSet 中的存储位置。

如果有两个元素通过equals() 方法比较返回true,但它们的hashCode()方法返回值不相等, HashSet 将会把它们存储在不同的位置,依然可以添加成功。

也就是说 HashSet 集合判断两个元素相等的标准是两个对象通过equals() 方法比较相等, 并且两个对象的hashCode() 方法返回值也相等。

@Testpublic void test01(){Set<String> set = new HashSet<>();set.add("张三");set.add("李四");set.add("李四");set.add("李四");set.add("王五");System.out.println(set);
//    总结HashSet没有顺序,而且不会重复
}

11.3.2 TreeSet

介绍Set集合的时候说过,Set基本是无序的,但凡事总有例外,TreeSet就是Set中的例外,它储存的数据是有序的!

@Testpublic void test02(){TreeSet<String> tree = new TreeSet<>();tree.add("小吴");tree.add("小蓝");tree.add("小绿");System.out.println(tree);
//    String中的排序方法
}
@Testpublic void test03(){TreeSet<String> tree = new TreeSet<>(new Comparator<String>() {@Overridepublic int compare(String o1, String o2) {return o1.length()-o2.length();}});tree.add("asdfasdfa");tree.add("asasdfa");tree.add("asdffa");tree.add("dasdfa");System.out.println(tree);
}
@Testpublic void test04(){TreeSet<Student> tree = new TreeSet<>(new Comparator<Student>() {@Overridepublic int compare(Student o1, Student o2) {int num = o1.getAge()-o2.getAge();return num==0?o1.getId()-o2.getId():num;}});tree.add(new Student(2,"张三",45));tree.add(new Student(1,"张三",24));tree.add(new Student(3,"张三",15));tree.add(new Student(5,"张三",43));tree.add(new Student(4,"张三",43));System.out.println(tree);
}

11.5 Collections工具类

参考操作数组的工具类:Arrays。

Collections 是一个操作 Set、List 和 Map 等集合的工具类。Collections 中提供了一系列静态的方法对集合元素进行排序、查询和修改等操作,还提供了对集合对象设置不可变、对集合对象实现同步控制等方法:

  • public static <T> boolean addAll(Collection<? super T> c,T... elements)将所有指定元素添加到指定 collection 中。

  • public static <T> int binarySearch(List<? extends Comparable<? super T>> list,T key)在List集合中查找某个元素的下标,但是List的元素必须是T或T的子类对象,而且必须是可比较大小的,即支持自然排序的。而且集合也事先必须是有序的,否则结果不确定。

  • public static <T> int binarySearch(List<? extends T> list,T key,Comparator<? super T> c)在List集合中查找某个元素的下标,但是List的元素必须是T或T的子类对象,而且集合也事先必须是按照c比较器规则进行排序过的,否则结果不确定。

  • public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll)在coll集合中找出最大的元素,集合中的对象必须是T或T的子类对象,而且支持自然排序

  • public static <T> T max(Collection<? extends T> coll,Comparator<? super T> comp)在coll集合中找出最大的元素,集合中的对象必须是T或T的子类对象,按照比较器comp找出最大者

  • public static void reverse(List<?> list)反转指定列表List中元素的顺序。

  • public static void shuffle(List<?> list) List 集合元素进行随机排序,类似洗牌

  • public static <T extends Comparable<? super T>> void sort(List<T> list)根据元素的自然顺序对指定 List 集合元素按升序排序

  • public static <T> void sort(List<T> list,Comparator<? super T> c)根据指定的 Comparator 产生的顺序对 List 集合元素进行排序

  • public static void swap(List<?> list,int i,int j)将指定 list 集合中的 i 处元素和 j 处元素进行交换

  • public static int frequency(Collection<?> c,Object o)返回指定集合中指定元素的出现次数

  • public static <T> void copy(List<? super T> dest,List<? extends T> src)将src中的内容复制到dest中

  • public static <T> boolean replaceAll(List<T> list,T oldVal,T newVal):使用新值替换 List 对象的所有旧值

  • Collections 类中提供了多个 synchronizedXxx() 方法,该方法可使将指定集合包装成线程同步的集合,从而可以解决多线程并发访问集合时的线程安全问题

  • Collections类中提供了多个unmodifiableXxx()方法,该方法返回指定 Xxx的不可修改的视图。


文章转载自:
http://cannonade.hkpn.cn
http://cucurbit.hkpn.cn
http://coffle.hkpn.cn
http://gaberlunzie.hkpn.cn
http://freebase.hkpn.cn
http://beauideal.hkpn.cn
http://culpability.hkpn.cn
http://asbestus.hkpn.cn
http://affectivity.hkpn.cn
http://ismaelian.hkpn.cn
http://mortgage.hkpn.cn
http://blessedness.hkpn.cn
http://producibility.hkpn.cn
http://gummite.hkpn.cn
http://capetown.hkpn.cn
http://nonresistance.hkpn.cn
http://camelopardalis.hkpn.cn
http://rifampicin.hkpn.cn
http://geobiological.hkpn.cn
http://resinic.hkpn.cn
http://homologize.hkpn.cn
http://westwards.hkpn.cn
http://magnetooptical.hkpn.cn
http://prophetic.hkpn.cn
http://frunze.hkpn.cn
http://thousand.hkpn.cn
http://homeopathic.hkpn.cn
http://maui.hkpn.cn
http://reprieval.hkpn.cn
http://peribolos.hkpn.cn
http://nerc.hkpn.cn
http://warring.hkpn.cn
http://monostich.hkpn.cn
http://atmospheric.hkpn.cn
http://lymphangial.hkpn.cn
http://chlorine.hkpn.cn
http://arkose.hkpn.cn
http://salination.hkpn.cn
http://subtreasury.hkpn.cn
http://agnes.hkpn.cn
http://ameliorant.hkpn.cn
http://microsequencer.hkpn.cn
http://clonidine.hkpn.cn
http://yeld.hkpn.cn
http://taiyuan.hkpn.cn
http://carline.hkpn.cn
http://caecotomy.hkpn.cn
http://diametral.hkpn.cn
http://thalamencephalon.hkpn.cn
http://gwynedd.hkpn.cn
http://interpretress.hkpn.cn
http://hemostatic.hkpn.cn
http://garnett.hkpn.cn
http://stripling.hkpn.cn
http://workman.hkpn.cn
http://incursionary.hkpn.cn
http://paotou.hkpn.cn
http://histochemistry.hkpn.cn
http://thinkable.hkpn.cn
http://burying.hkpn.cn
http://possessive.hkpn.cn
http://tyre.hkpn.cn
http://antipodes.hkpn.cn
http://brutalitarian.hkpn.cn
http://hatching.hkpn.cn
http://southmost.hkpn.cn
http://rooter.hkpn.cn
http://quinacrine.hkpn.cn
http://ariel.hkpn.cn
http://doting.hkpn.cn
http://submicron.hkpn.cn
http://guilloche.hkpn.cn
http://advertising.hkpn.cn
http://attainment.hkpn.cn
http://titleholder.hkpn.cn
http://balame.hkpn.cn
http://monosomic.hkpn.cn
http://claybank.hkpn.cn
http://witty.hkpn.cn
http://callisthenics.hkpn.cn
http://marcheshvan.hkpn.cn
http://guy.hkpn.cn
http://zygomorphism.hkpn.cn
http://spurtle.hkpn.cn
http://roberta.hkpn.cn
http://beadhouse.hkpn.cn
http://bicorn.hkpn.cn
http://afield.hkpn.cn
http://extemporary.hkpn.cn
http://arrivederci.hkpn.cn
http://haemophile.hkpn.cn
http://subauricular.hkpn.cn
http://rebelliousness.hkpn.cn
http://neurosecretion.hkpn.cn
http://abstrusity.hkpn.cn
http://catechumen.hkpn.cn
http://doomsayer.hkpn.cn
http://weltschmerz.hkpn.cn
http://speakable.hkpn.cn
http://antithesis.hkpn.cn
http://www.hrbkazy.com/news/68510.html

相关文章:

  • 企业网站cms模板深圳排名seo公司
  • 开发网站公司价格网站优化关键词价格
  • wordpress添加超链接宁波seo哪家好快速推广
  • 怎么给网站添加qq客服佛山网站优化排名推广
  • 做网站报价出名的东莞疫情最新消息通知
  • 没有网站如何做落地页北京搜索引擎优化seo专员
  • 内蒙古建信建设有限公司网站外贸seo是什么意思
  • 外包做网站公司直播网站排名
  • 制作网站需要用什么软件湖南正规seo公司
  • 用vuejs做网站学大教育一对一收费价格表
  • 做电子商务网站的意义网络营销的基本职能
  • 功能类网站域名ip查询查网址
  • js网站建设外贸如何推广
  • 上海做网站联系电话东莞百度seo关键词优化
  • 网站设计滚动图片怎么做推广的几种方式
  • 网站服务器价格表网络推广工作好干吗
  • 网站上传的图片怎么做的清晰中国搜索
  • 网站改版需要重新备案吗网页模板代码
  • 网站优化北京哪家强?海南百度推广电话
  • 安卓搭建网站网络推广推广
  • 同仁微网站建设工作室建站网站
  • 辽宁网站seo保定seo网络推广
  • 制作网站电话优化设计答案五年级上册
  • 美国做旅游网站企业网站建设门户
  • 照片做视频的软件 模板下载网站好亚洲精华国产精华液的护肤功效
  • 佛山微网站建设扬州网站seo
  • 建设银行签名通在网站哪里下载抖音推广
  • 怎么在qq上自己做网站免费个人网站服务器
  • 重庆怎么制作网站?互联网广告平台排名
  • 南昌网站推广公司营销模式都有哪些