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

莱西网站制作wordpress 架构图

莱西网站制作,wordpress 架构图,建设网银登录网站,包头建设安全协会网站1 List 1.1 List的特点 List接口继承自Collection接口List是有序集合#xff0c;存取顺序一致允许存储重复元素 1.2 List的特有方法【带索引】 public void add(int index, E element);public E get(int index)public E remove(int index)#xff1a;返回移除元素public …1 List 1.1 List的特点 List接口继承自Collection接口List是有序集合存取顺序一致允许存储重复元素 1.2 List的特有方法【带索引】 public void add(int index, E element);public E get(int index)public E remove(int index)返回移除元素public E set(int index, E element)替换指定位置的元素返回更新前元素遍历Listforgetindexiterator、foreach非特有 使用示例 public static void main(String[] args) {ListString list new ArrayList();//1.list.add(a);list.add(b);list.add(b);//可重复list.add(d);System.out.println(list);//[a, b, b, d]重写了toString直接打印列表 而不是地址//2.list.remove(2);System.out.println(list);//[a, b, d]//3.String s list.get(1);System.out.println(s);//b//4.String result list.set(2, c);System.out.println(result);//dSystem.out.println(list);//[a, b, c]}1.3 List的实现类 ArrayList数组实现查询快增删慢 LinkedList链表实现查询慢增删快 LinkedList特有方法不能用多态 addFirst(E, e) getFirst removeFirstaddLast(E, e) getLast removeLastpush(E e)pop() 使用示例 public static void main(String[] args) {LinkedListString list new LinkedList();list.add(b);list.add(c);System.out.println(list);//[b, c]list.addFirst(a);System.out.println(list);//[a, b, c]list.addLast(d);System.out.println(list);//[a, b, c, d]list.push(1);//addFirstSystem.out.println(list);//[1, a, b, c, d]list.pop();//removeFirstSystem.out.println(list);//[a, b, c, d]String first list.getFirst();String last list.getLast();System.out.println(first last);// a dString s1 list.removeFirst();String s2 list.removeLast();System.out.println(s1 s2);// a dSystem.out.println(list);//[b,c]}2 Set 2.1 Set的特点 Set接口继承自Collection接口不允许存储重复元素无索引不能使用普通for循环遍历 2.2 Set的实现类 HashSet无序集合、不同步、底层是哈希表查询快 使用HashSet public static void main(String[] args) {SetString set new HashSet();set.add(1);set.add(2);set.add(3);set.add(3);IteratorString it set.iterator();while(it.hasNext()){System.out.print(it.next() );}System.out.println();for(String s: set){System.out.print(s );}}2.3 哈希表 哈希值十进制整数系统随机给出。逻辑地址而非物理地址 hashCode方法源码没有方法体 native代表调用本地操作系统的方法 public native int hashCode();数据结构 jdk1.8之前数组链表 使用链表处理冲突同一hash值的链表都存储在一个链表里。hash值相等的元素较多时通过key值依次查找的效率较低 jdk1.8之后数组链表红黑树提高查询速度 哈希表存储采用数组链表红黑树实现当链表长度超过阈值8时将链表转换为红黑树这样大大减少了查找时间。 Set集合判断元素是否重复在调用add方法的时候会调用元素的hashCode方法和equals方法。如果hashCode一样则发生了哈希冲突调用equals方法判断两个元素是否相同不相同时才存入表中。 前提要重写equals方法和hashCode方法 原因不重写默认的equals()判断的是两个对象的引用指向的是不是同一个对象而hashCode()根据对象地址生成一个整数数值hashCode()的修饰符为native,表明该方法是否操作系统实现java调用操作系统底层代码获取哈希值。 自定义类型存入HashSet 定义Person类 import java.util.Objects;public class Person {String name;int age;public Person(String name, int age) {this.name name;this.age age;}Override//打印属性信息public String toString() {return Person{ name name \ , age age };}Override//比较属性值public boolean equals(Object o) {if (this o) return true;if (o null || getClass() ! o.getClass()) return false;Person person (Person) o;return age person.age Objects.equals(name, person.name);}Override//属性的hash值public int hashCode() {return Objects.hash(name, age);}定义测试类 import java.util.HashSet; import java.util.Set;public class HashSetTest {public static void main(String[] args) {Set Person persons new HashSet();Person p1 new Person(张三,30);Person p2 new Person(张三,25);Person p3 new Person(张三,30);System.out.println(p1.hashCode());//重写后24022550System.out.println(p3.hashCode());//重写后24022550persons.add(p1);persons.add(p2);persons.add(p3);//重写了equals 认为同名同姓是一个人 重写前比较对象地址//重写了toString 打印对象属性信息 重写前是包名.类型16进制哈希值//重写了hashCode 重写前是对象地址的hash值System.out.println(persons);//[Person{name张三, age30}, Person{name张三, age25}]} }2.4 LinkedHashSet 底层是哈希表数组链表/红黑树链表多加一条链表用来记录元素的存储顺序保证元素有序。 import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set;public class LinkedHashSetTest {public static void main(String[] args) {SetString hs new HashSet();hs.add(def);hs.add(abc);hs.add(ghi);System.out.println(hs);//存取无序 [abc, def, ghi]SetString lhs new LinkedHashSet();lhs.add(def);lhs.add(abc);lhs.add(ghi);System.out.println(lhs);//存取有序 [def, abc, ghi]} }3 可变参数 JDK1.5之后出现的新特性。当方法的参数列表数据类型已确定但参数个数不确定就可以使用可变参数。 修饰符 返回值类型 方法名数据类型…遍历名{} 原理底层是一个数组根据参数个数的不同创建不同长度的数组来存储这些参数传递的参数个数。 public static void main(String[] args) {int result add(1,2,3,4,5);System.out.println(result);}//计算0~n个整数和的方法public static int add(int...nums){int sum 0;for (int i 0; i nums.length; i) {sum nums[i];}return sum;}4 Collections 4.1 常用功能 addAll往集合中添加一些元素shuffle打乱集合顺序sort按默认规则排序sort按指定规则排序。this.排序属性 - 参数.排序属性升序 在自定义类中重写 //implement ComparablePerson Overridepublic int compareTo(Person o) {//初始认为元素相同//return 0;//自定义://return this.getAge() - o.getAge();//按年龄升序//return this.getName() - o.getName();//按名字升序//组合排序int result this.getAge() - o.getAge();if(result 0){return this.getName() - o.getName();}return result;}示例1 在定义类时实现接口并重写compareTo public static void main(String[] args) {ArrayListString list new ArrayList();Collections.addAll(list,a,b,c,d,e);System.out.println(list);//[a, b, c, d, e]Collections.shuffle(list);System.out.println(list);//[e, b, c, a, d]Collections.sort(list);//默认规则升序排序System.out.println(list);//[a, b, c, d, e]ArrayListPerson persons new ArrayList();persons.add(new Person(张三,50));//sort使用前提是实现了Comparable接口重写CompareTo方法persons.add(new Person(李四,20));//对自定义类排序Collections.sort(persons);System.out.println(persons);//[Person{name李四, age20}, Person{name张三, age50}]}示例2 在调用sort时 通过匿名对象进行重写 public static void main(String[] args) {ArrayListInteger list new ArrayList();Collections.addAll(list,1,2,3,4,5,6,7);Collections.shuffle(list);Collections.sort(list, new ComparatorInteger() {Overridepublic int compare(Integer o1, Integer o2) {return o1 - o2;//升序//return o2 - o1;//降序}});System.out.println(list);}
http://www.yutouwan.com/news/14524/

相关文章:

  • 开源网站源码下载成全视频免费高清观看在线动漫电影
  • 我想做个网站怎么做的辽宁省建设工程信息网专家库怎么入
  • 产品型网站销售型网站怎么做
  • 360任意看地图网站自己设计服装的app免费
  • 做外贸网站一般多少钱广州网站ui设计
  • 外卖做的比较好的网站企业咨询是什么工作
  • 建设摩托官方网站东莞桥头网站设计
  • 电脑网站兼职在哪里做织梦帝国和wordpress
  • 番禺 网站建设合肥有什么好的网站建设公司好
  • 网站建设参考书网站在线建站
  • 什么软件可以找做网站的seo推广软件代理
  • 专门做儿童的店铺网站个人可以做宣传片视频网站
  • 做一网站要学些什么软件中国建筑官网超高层
  • 网站html静态化做好一个网站需要多久
  • 淮北住房和城乡建设局门户网站北京市住房和城乡建设官网
  • 技术支持 桂林网站建设园林景观设计公司需要什么资质
  • 沧州网站建设建站系统wordpress 阿里百秀主题
  • 网站改版做301网络运维工程师有前途吗
  • 做网站需要画原型图么洛阳哪有做公司网站的
  • 网站做宣传阿里云网络服务器
  • 做网站的登陆功能最好免费高清视频下载
  • php网站开发程序填空题如何给网店做推广
  • 网络推广的方式和途径有哪些如何做网站导航栏的seo优化
  • 中国风html5网站模板票务网站开发
  • 中山本地网站建设聊城感染最新数据
  • 做木业网站怎样起名奎屯网站建设
  • 网站界面优化html5 图片展示网站
  • 网站建设要学哪些visual studio2005做网站
  • 安徽网站建设公司哪家好重庆市建设工程造价信息官网
  • 下载网站源文件网站免费观看