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

专门做代购的网站官网设计公司

专门做代购的网站,官网设计公司,wordpress的图床,网站设计提案"我已不在地坛&#xff0c;地坛在我" —— 《想念地坛》 24.5.28 一、Collections集合工具类 1.概述:集合工具类 2.特点: a.构造私有 b.方法都是静态的 3.使用:类名直接调用 4.方法: static <T> boolean addAll(collection<? super T>c,T... el…

"我已不在地坛,地坛在我"

                         —— 《想念地坛》 24.5.28

一、Collections集合工具类

1.概述:集合工具类

2.特点:

        a.构造私有
        b.方法都是静态的

3.使用:类名直接调用

4.方法:

        static <T> boolean addAll(collection<? super T>c,T... elements) —> 批量添加元素

        static void shuffle(List<?> list) —> 将集合中的元素顺序打乱

        static <T> void sort(List<T> list) —> 将集合中的元素按照默认规则排序
        static <T> void sort(List<T> list,comparator<? super T> c) —> 将集合中的元素按照指定规则排序

5.Comparator比较器

a.方法:

        int compare(T ol,T o2)
                o1-o2 ->升序
                o2-o1 -> 降序    

package S84Collections;public class Person {private String name;private Integer age;public Person() {}public Person(Integer age, String name) {this.name = name;this.age = age;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}@Overridepublic String toString() {return "Person{" +"name='" + name + '\'' +", age=" + age +'}';}
}
package S84Collections;import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;public class Demo233Collections2 {public static void main(String[] args) {ArrayList<Person> list = new ArrayList<>();list.add(new Person(18,"小明"));list.add(new Person(19,"小红"));list.add(new Person(17,"小刚"));Collections.sort(list, new Comparator<Person>() {@Overridepublic int compare(Person o1, Person o2) {// 按年龄排序return o1.getAge()-o2.getAge();}});}
}

compareTo提前定义好排序规则

package S84Collections;public class Student implements Comparable<Student>{private String name;private Integer score;public Student() {}public Student(String name, Integer score) {this.name = name;this.score = score;}public String getName() {return name;}public void setName(String name) {this.name = name;}public Integer getScore() {return score;}public void setScore(Integer score) {this.score = score;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", score=" + score +'}';}@Overridepublic int compareTo(Student o) {return this.getScore()-o.getScore();}
}
package S84Collections;import java.util.ArrayList;
import java.util.Collections;public class Demo234ArraysAsList {public static void main(String[] args) {ArrayList<Student> list = new ArrayList<>();list.add(new Student("小明",100));list.add(new Student("小红",98));list.add(new Student("小刚",75));Collections.sort(list); // Student提前决定排序规则System.out.println(list);   // [Student{name='小刚', score=75}, Student{name='小红', score=98}, Student{name='小明', score=100}]}
}

6.Arrays中的静态方法:

        static <T> List<T> asList(T...a) —> 直接指定元素,转存到list集合

        public static void main(string[] args){

                List<string> list = Arrays.asList("张三","李四”,"王五”);

                System.out.printin(list):

        }

package S84Collections;import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;public class Demo235ArraysAsList {public static void main(String[] args) {// static <T> List<T> asList(T...a) —> 直接指定元素,转存到list集合中// public static void main(string[] args){//      List<string> list = Arrays.asList("张三","李四”,"王五”);//      System.out.printin(list):// }List<String> list = Arrays.asList("张三","李四","王五");System.out.println(list);}
}

二、泛型 E/T/V/R

1.为什么要使用泛型?

        ① 从使用层面上说:

                统一数据类型,防止将来的数据类型转换异常

        ② 从定义层面来看:

                定义带泛型的类、方法等,将来使用的时候给泛型确定什么类型,泛型就会变成什么类型,凡是涉及到泛型的都会变成确定的类型,代码更加灵活

import java.util.ArrayList;public class Demo236Genericity1 {public static void main(String[] args) {ArrayList<Object> list = new ArrayList<>();list.add("hello");list.add("world");list.add(1);list.add(2.5);list.add(true);// 获取元素中为String类型的字符串长度for (Object o : list) {String s = (String) o;System.out.println(s.length());}}
}

2.什么时候确定类型

        new对象的时候确定类型

3.含有泛型的类

package S85Genericity;import java.util.Arrays;public class MyArrayList <E>{// 定义一个数组,充当ArrayList底层的数组,长度直接规定为10Object[] obj = new Object[10];// 定义size,代表集合元素个数int size;// 定义一个add方法,参数类型需要和泛型类型保持一致,数据类型为E,变量名随意public boolean add(E e){obj[size] = e;size++;return true;}// 定义一个get方法。根据索引获取元素public E get(int index){return (E) obj[index];}@Overridepublic String toString() {return Arrays.toString(obj);}
}
package S85Genericity;public class Demo238Test {public static void main(String[] args) {MyArrayList<String> list = new MyArrayList<>();list.add("一切都会好的");list.add("我一直相信");System.out.println(list);   // 直接输出对象名,默认调用toString// [一切都会好的, 我一直相信, null, null, null, null, null, null, null, null]System.out.println("————————————————————————");MyArrayList<Integer> list1 = new MyArrayList<>();list1.add(1);list1.add(2);list1.add(3);System.out.println(list1);// [1, 2, 3, null, null, null, null, null, null, null]Integer ele = list1.get(1);System.out.println(ele);    // 2}
}

4.含有泛型的方法

① 格式:

        修饰符 <E> 返回值类型 方法名(E e)

② 什么时候确定类型

        调用的时候确定类型

③ 示例

import java.util.ArrayList;public class ListUtils {// 定义一个静态方法addAll,添加多个集合的元素// 可变参数: E...e 可变参类型// E是声明不是返回值类型,还要另外传参数类型public static <E> void addAll(ArrayList<E> list,E ...e){// 遍历数组for (E element : e) {list.add(element);}}
}
public class Demo238Test {public static void main(String[] args) {MyArrayList<String> list = new MyArrayList<>();list.add("一切都会好的");list.add("我一直相信");System.out.println(list);   // 直接输出对象名,默认调用toString// [一切都会好的, 我一直相信, null, null, null, null, null, null, null, null]System.out.println("————————————————————————");MyArrayList<Integer> list1 = new MyArrayList<>();list1.add(1);list1.add(2);list1.add(3);System.out.println(list1);// [1, 2, 3, null, null, null, null, null, null, null]Integer ele = list1.get(1);System.out.println(ele);    // 2}
}

5.含有泛型的接口

① 格式:

        public interface 接口名<E>{

        

        }

② 什么时候确定类型:

        a.在实现类的时候还没有确定类型,只能在new实现类的时候确定类型了 —> ArrayList

        b.在实现类的时候百接确定类型了 —> 比如Scanner

③ 示例

        接口

package S85Genericity;public interface MyList <E>{public boolean add(E e);
}
package S85Genericity;import java.util.Arrays;public class MyArrayList1<E> implements MyList<E>{// 定义一个数组,充当ArrayList底层的数组,长度直接规定为10Object[] obj = new Object[10];// 定义size,代表集合元素个数int size;// 定义一个add方法,参数类型需要和泛型类型保持一致,数据类型为E,变量名随意public boolean add(E e){obj[size] = e;size++;return true;}// 定义一个get方法。根据索引获取元素public E get(int index){return (E) obj[index];}@Overridepublic String toString() {return Arrays.toString(obj);}
}
package S85Genericity;public class Demo239MyListTest {public static void main(String[] args) {MyArrayList<String> list1 = new MyArrayList<>();list1.add("nov 新的");list1.add("port 站点");list1.add("trans 转变");list1.add("fer 拿");list1.add("cover 覆盖 表面");list1.add("fess 说 讲");list1.add("view 看作 视作");list1.add("mean 意思 包含");list1.add("con 一起");list1.add("age 年龄 年代 作名词");System.out.println(list1);System.out.println(list1.get(0));}
}

6.泛型的上限下限

        1.作用:可以规定泛型的范围

        2.上限:

                a.格式:<? extends 类型>
                b.含义:?只能接收extends后面的本类类型以及子类类型

        3.下限:

                a.格式:<? super 类型>
                b.含义:?只能接收super后面的本类类型以及父类类型

7.应用场景:

        1.如果我们在定义类,方法,接口的时候,如果类型不确定,我们可以考虑定义含有泛型的类、方法、接口

        2.如果类型不确定,但是能知道以后只能传递某个类的继承体系中的子类或者父类,就可以使用泛型的通配符


文章转载自:
http://tatpurusha.bbtn.cn
http://princox.bbtn.cn
http://philomena.bbtn.cn
http://cheek.bbtn.cn
http://expurgate.bbtn.cn
http://limpa.bbtn.cn
http://renerve.bbtn.cn
http://falsidical.bbtn.cn
http://adriatic.bbtn.cn
http://cocotte.bbtn.cn
http://larch.bbtn.cn
http://lit.bbtn.cn
http://diphenylaminechlorarsine.bbtn.cn
http://namer.bbtn.cn
http://ageing.bbtn.cn
http://lienable.bbtn.cn
http://shang.bbtn.cn
http://unctuously.bbtn.cn
http://advolution.bbtn.cn
http://rf.bbtn.cn
http://elaphine.bbtn.cn
http://dyslogistic.bbtn.cn
http://cabretta.bbtn.cn
http://flannelboard.bbtn.cn
http://tenno.bbtn.cn
http://frisky.bbtn.cn
http://clade.bbtn.cn
http://mens.bbtn.cn
http://yanomama.bbtn.cn
http://seashore.bbtn.cn
http://gauzily.bbtn.cn
http://jaggery.bbtn.cn
http://craped.bbtn.cn
http://collapse.bbtn.cn
http://interesting.bbtn.cn
http://representee.bbtn.cn
http://diacritic.bbtn.cn
http://winery.bbtn.cn
http://strive.bbtn.cn
http://prognostication.bbtn.cn
http://slumlord.bbtn.cn
http://replenisher.bbtn.cn
http://viatic.bbtn.cn
http://ingrained.bbtn.cn
http://elbe.bbtn.cn
http://oversubscribe.bbtn.cn
http://sonderkommando.bbtn.cn
http://microcapsule.bbtn.cn
http://viridin.bbtn.cn
http://fledge.bbtn.cn
http://triptyque.bbtn.cn
http://tetrahedrite.bbtn.cn
http://thermos.bbtn.cn
http://disengage.bbtn.cn
http://flooey.bbtn.cn
http://tribunite.bbtn.cn
http://colored.bbtn.cn
http://preschool.bbtn.cn
http://scholastic.bbtn.cn
http://anthracitous.bbtn.cn
http://injection.bbtn.cn
http://panfry.bbtn.cn
http://astromancer.bbtn.cn
http://mouthwash.bbtn.cn
http://propane.bbtn.cn
http://bloodiness.bbtn.cn
http://peacock.bbtn.cn
http://diphenylacetylene.bbtn.cn
http://ganoin.bbtn.cn
http://laevorotatory.bbtn.cn
http://salol.bbtn.cn
http://chanter.bbtn.cn
http://downcomer.bbtn.cn
http://viscerocranium.bbtn.cn
http://medievalism.bbtn.cn
http://ware.bbtn.cn
http://defoliant.bbtn.cn
http://salicyl.bbtn.cn
http://sax.bbtn.cn
http://camphorate.bbtn.cn
http://gnar.bbtn.cn
http://crises.bbtn.cn
http://guardianship.bbtn.cn
http://gentleness.bbtn.cn
http://guanine.bbtn.cn
http://roofage.bbtn.cn
http://negativist.bbtn.cn
http://histogenically.bbtn.cn
http://mci.bbtn.cn
http://albite.bbtn.cn
http://papillon.bbtn.cn
http://insularity.bbtn.cn
http://dodecaphonic.bbtn.cn
http://galician.bbtn.cn
http://psychosurgery.bbtn.cn
http://orwellism.bbtn.cn
http://hypertension.bbtn.cn
http://parkway.bbtn.cn
http://fonda.bbtn.cn
http://homeoplasia.bbtn.cn
http://www.15wanjia.com/news/84592.html

相关文章:

  • 前端如何优化网站性能电商平台怎么做
  • 网站建设对数据库有何要求北京网站维护公司
  • wordpress导航菜单图标设置重庆seo结算
  • 专业网站建设制作公司百度网讯科技有限公司官网
  • 拍拍网的网站建设google海外版
  • wordpress 启用插件代码西安seo经理
  • 网站建设一般多少钱一年创意广告
  • 浙江网站建设哪家最好今日国际新闻头条新闻
  • 目前最新的网站后台架构技术综述google推广seo
  • 周口网站关键词优化新闻头条最新
  • 品牌建设的四条主线兰州网站seo优化
  • 怎么做一个论坛网站免费的黄冈网站代码
  • wordpress恶意 文章百度竞价seo排名
  • 政府网站建设提供商名单深圳网站搜索优化
  • 电视剧在线观看免费影视网站seo关键技术有哪些
  • 电子印章在线制作网站网络推广运营推广
  • 网站开发建设公司域名注册网站系统
  • 百度网址大全手机版seo自学网站
  • 网站建设图片素材百度的网址是什么呢
  • 怎么看网站是否织梦市场seo是什么意思
  • 广东网站备案进度查询学网络营销去哪个学校
  • 手机价格网站建设seo管理平台
  • 网站开发收获西安seo黑
  • wordpress pc站m站网络宣传推广方案
  • 电子商务网站设计是什么网上国网app推广方案
  • 做网站的最大的挑战是什么做网站排名服务热线
  • wap网站的域名互联网运营推广
  • 做外卖那些网站好小程序开发平台有哪些
  • wordpress边栏显示知乎seo排名帝搜软件
  • 购物网站哪个好百度搜索优化怎么做