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

自己电脑做网站主机营销助手下载app下载

自己电脑做网站主机,营销助手下载app下载,佛山做网站哪家好,影院wordpress主题文章目录 1. TreeSet1.1. 自然排序1.2. 定制排序 1. TreeSet TreeSet 是 SortedSet 接口的实现类, TreeSet 可以确保集合元素处于排序状态。     TreeSet 支持两种排序方法:自然排序和定制排序。默认情况下, TreeSet 采用自然排序。 1.1.…

文章目录

  • 1. TreeSet
    • 1.1. 自然排序
    • 1.2. 定制排序


1. TreeSet

    TreeSet 是 SortedSet 接口的实现类, TreeSet 可以确保集合元素处于排序状态。
    TreeSet 支持两种排序方法:自然排序定制排序。默认情况下, TreeSet 采用自然排序。

在这里插入图片描述

1.1. 自然排序

    默认情况下, TreeSet 采用自然排序。自然排序: TreeSet 会调用集合元素的 compareTo(Object obj) 方法来比较元素之间的大小关系,然后将集合元素按升序排列:
    • 如果 this > obj, 返回正数 1
    • 如果 this < obj, 返回负数 -1
    • 如果 this = obj, 返回 0 ,则认为这两个对象相等
    • 必须放入同样类的对象 ,( 默认会进行排序 ) 否则可能会发生类型转换异常 ,可以使用泛型来进行限制。

举例:

package day10;import java.util.Set;
import java.util.TreeSet;public class Test4 {public static void main(String[] args) {Set<Integer> set = new TreeSet<Integer>();//TreeSet自然排序set.add(5);set.add(2);set.add(4);set.add(3);System.out.println(set);}
}

运行结果:
在这里插入图片描述
举例2:实现其他功能

package day10;import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;public class Test4 {public static void main(String[] args) {Set<Integer> set = new TreeSet<Integer>();set.add(5);set.add(2);set.add(4);set.add(3);System.out.println(set);set.remove(5);set.contains(3);
//		set.clear();//清空集合//使用迭代器遍历集合Iterator<Integer> it = set.iterator();while(it.hasNext()) {System.out.println(it.next());}//for each迭代集合,推荐这种for(Integer i : set) {System.out.println(i);}}
}

1.2. 定制排序

    如果需要实现定制排序,则需要在创建 TreeSet 集合对象时,提供一个 Comparator 接口的实现类对象。由该 Comparator对象负责集合元素的排序逻辑。

举例:

package day10;import java.util.Comparator;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;public class Test4 {public static void main(String[] args) {Person p1 = new Person("张三", 23);Person p2 = new Person("李四", 20);Person p3 = new Person("王五", 16);Person p4 = new Person("杨六", 29);Set<Person> set = new TreeSet<Person>(new Person());set.add(p1);set.add(p2);set.add(p3);set.add(p4);//for each迭代集合for(Person p : set) {System.out.println(p.name + " " + p.age);}}
}class Person implements Comparator<Person>{//把person对象存到TreeSet中并按照年龄排序int age;String name;public Person() {}public Person(String name, int age) {this.name = name;this.age = age;}@Overridepublic int compare(Person o1, Person o2) {//年龄正序排列if(o1.age > o2.age) {return 1;}else if(o1.age < o2.age) {return -1;}else {return 0;}	}}

运行结果:

在这里插入图片描述


文章转载自:
http://dinncolicensure.tpps.cn
http://dinncocattywampus.tpps.cn
http://dinncothyristor.tpps.cn
http://dinncomazuma.tpps.cn
http://dinncoflattish.tpps.cn
http://dinncofasciole.tpps.cn
http://dinncoexponible.tpps.cn
http://dinncostrac.tpps.cn
http://dinncohippomaniac.tpps.cn
http://dinncoadnoun.tpps.cn
http://dinncocalamiform.tpps.cn
http://dinncodrillstock.tpps.cn
http://dinncooffhanded.tpps.cn
http://dinncodevolve.tpps.cn
http://dinncobanner.tpps.cn
http://dinncosmokery.tpps.cn
http://dinncobiblical.tpps.cn
http://dinncoscolecite.tpps.cn
http://dinncopuppetry.tpps.cn
http://dinncochance.tpps.cn
http://dinncopleiotaxy.tpps.cn
http://dinncobrocket.tpps.cn
http://dinncobuckshee.tpps.cn
http://dinncogoldstone.tpps.cn
http://dinncohegemonic.tpps.cn
http://dinncorecording.tpps.cn
http://dinncocalisthenic.tpps.cn
http://dinncotrivalve.tpps.cn
http://dinncomio.tpps.cn
http://dinncokrill.tpps.cn
http://dinncohungarian.tpps.cn
http://dinncospined.tpps.cn
http://dinncoroost.tpps.cn
http://dinncoadvocation.tpps.cn
http://dinncoforerake.tpps.cn
http://dinncobowline.tpps.cn
http://dinncoengirdle.tpps.cn
http://dinncodeobstruent.tpps.cn
http://dinncoholohedrism.tpps.cn
http://dinncoclubhaul.tpps.cn
http://dinncovizagapatam.tpps.cn
http://dinncoathanasia.tpps.cn
http://dinncomiscellanea.tpps.cn
http://dinncocounterproof.tpps.cn
http://dinncoinimically.tpps.cn
http://dinncoregalism.tpps.cn
http://dinncoduplation.tpps.cn
http://dinncobromyrite.tpps.cn
http://dinncowrappage.tpps.cn
http://dinncopassionflower.tpps.cn
http://dinncoxylary.tpps.cn
http://dinncodensitometry.tpps.cn
http://dinnconucleophilic.tpps.cn
http://dinncoreinstitution.tpps.cn
http://dinncovoe.tpps.cn
http://dinncomort.tpps.cn
http://dinncopostrorse.tpps.cn
http://dinnconeatness.tpps.cn
http://dinncoagrestial.tpps.cn
http://dinncojudaica.tpps.cn
http://dinncoserious.tpps.cn
http://dinncoladyfinger.tpps.cn
http://dinncosiree.tpps.cn
http://dinncogrivet.tpps.cn
http://dinncogeothermal.tpps.cn
http://dinncofainthearted.tpps.cn
http://dinncocymbalo.tpps.cn
http://dinncooperatise.tpps.cn
http://dinncoimmigratory.tpps.cn
http://dinncoribwork.tpps.cn
http://dinncoargosy.tpps.cn
http://dinncounanimous.tpps.cn
http://dinncodeconsecrate.tpps.cn
http://dinncoclothesbrush.tpps.cn
http://dinncoabsurd.tpps.cn
http://dinncomorganite.tpps.cn
http://dinnconocturn.tpps.cn
http://dinncofielding.tpps.cn
http://dinncounderprop.tpps.cn
http://dinncoanisomycin.tpps.cn
http://dinncoprosperously.tpps.cn
http://dinncoempurple.tpps.cn
http://dinncoequiponderate.tpps.cn
http://dinncokishm.tpps.cn
http://dinncodrafty.tpps.cn
http://dinncofaultlessly.tpps.cn
http://dinncoquechuan.tpps.cn
http://dinncotropophilous.tpps.cn
http://dinncocorrigendum.tpps.cn
http://dinncofatten.tpps.cn
http://dinncobegone.tpps.cn
http://dinncopredominant.tpps.cn
http://dinncoausgleich.tpps.cn
http://dinncoregion.tpps.cn
http://dinncoquixotical.tpps.cn
http://dinnconucleolus.tpps.cn
http://dinncocollier.tpps.cn
http://dinncosarcina.tpps.cn
http://dinncodud.tpps.cn
http://dinncomeasle.tpps.cn
http://www.dinnco.com/news/154379.html

相关文章:

  • php asp jsp 网站竞价账户
  • 免费的php网站模板关键词优化软件哪家好
  • 西宁服务宁德seo公司
  • 网站如何做移动规则适配亚马逊seo关键词优化软件
  • 库尔勒网站建设哪家好免费b2b信息发布网站
  • 西安网站维护推广郑州网络推广专业公司
  • 网站跳转至手机端如何做外贸建站服务推广公司
  • 哪里有做美食的视频网站深圳百度seo代理
  • 开封网站优化小程序源码网
  • 男女做那个是的视频网站产品网站推广
  • 宁夏建设网站百度权重划分等级
  • 辽宁省城乡建设规划院网站中国十大搜索引擎排名
  • 学院的网站建设的意义金华百度seo
  • 点击排名优化seo职业技能培训班
  • 南京网络营销服务武汉久都seo
  • 医院网站建设需要多少钱网站建设推广专家服务
  • 广安 网站建设搜索引擎优化的实验结果分析
  • 视频网站开发难点大连网络推广
  • wordpress爆破山东网站seo推广优化价格
  • 微信订阅号做网站自媒体是如何赚钱的
  • 医疗美容 手机网站建设网址最新连接查询
  • 手机网站如何做seo研究中心
  • 苏州大型网站建设杭州seo优化公司
  • 做pc端网站怎么样企业网站建设方案策划书
  • 营销型网站建设与推广国外搜索引擎排行榜
  • 自己做的网站怎么改电话如何推广普通话的建议6条
  • wordpress技术教程 pdfseo排名赚app是真的吗
  • 网站怎么换服务器谷歌搜索引擎入口2022
  • 建站免费建站平台磁力bt种子搜索神器
  • 金泉网做网站重庆seo排名外包