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

h5网站制作视频网站平台推广方案

h5网站制作视频,网站平台推广方案,网页设计的首页版式,苏州园区排序集合的对象 (Sorting objects of the Collection) This concept is related to sorting and here we will see how to sort objects on the Collection? 这个概念与排序有关#xff0c;在这里我们将看到如何对Collection上的对象进行排序#xff1f; In java, we have u… 排序集合的对象 (Sorting objects of the Collection) This concept is related to sorting and here we will see how to sort objects on the Collection? 这个概念与排序有关在这里我们将看到如何对Collection上的对象进行排序 In java, we have utility class Collections which provide various methods to perform various task and one of the methods of Collection class is related to sorting like sort(). 在Java中我们有实用程序类Collections它提供了执行各种任务的各种方法并且Collection类的方法之一与sort()之类的排序有关。 We can implement sorting on Collection object in two ways: 我们可以通过两种方式对Collection对象实施排序 By using ComparableBy using ComparatorWhen we call Collections.sort(). It sorts an object based on natural sorting or default sorting(i.e Ascending order) thats is specified in compareTo() method. 当我们调用Collections.sort()时 。 它根据compareTo()方法中指定的自然排序或默认排序(即升序)对对象进行排序。 When we call Collections.sort(Comparator). It sorts an object based on customized sorting (i.e Ascending order or Descending order) thats is specified in compare() method of Comparator. 当我们调用Collections.sort(Comparator)时 。 它根据在Comparator的compare()方法中指定的自定义排序(即升序或降序)对对象进行排序。 We will see the sorting ways one by one... 我们将一一看到排序方式... 1)通过使用比较器 (1) By using Comparator) If we pass the Comparator object in Collection class constructor then our compare() method will be executed. 如果我们在Collection类构造函数中传递Comparator对象则将执行compare()方法。 When we want customize sorting then we should go for Comparator. 当我们想要自定义排序时我们应该选择比较器。 It is possible to implement customized sorting by using Comparator interface. (Customized sorting means that according to our need whether it is ascending or descending). 使用Comparator接口可以实现自定义排序。 (自定义排序意味着根据我们的需要是升序还是降序)。 Example: 例 import java.util.*; class TreeSetClass { public static void main(String[] args) { // Here we are passing Comparator object in Collection // class constructor for custoize sorting TreeSet ts new TreeSet(new CustomizeSorting()); // adding elements to TreeSet ts.add(10); ts.add(40); ts.add(30); ts.add(20); // Customized Sorted List System.out.println(Customize sorting : ts); } } // Here we are implementing Comparator interface class CustomizeSorting implements Comparator { // Here we are overrding compare() method of Comparator public int compare(Object obj1, Object obj2) { Integer i1 (Integer) obj1; Integer i2 (Integer) obj2; return -i1.compareTo(i2); } } Output 输出量 E:\Programsjavac TreeSetClass.java E:\Programsjava TreeSetClass Customize sorting :[40, 30, 20, 10] 2)使用可比接口 (2) By using Comparable interface) For predefined Comparable classes default natural sorting is already available. 对于预定义的可比较类默认的自然排序已可用。 For predefined Non-Comparable classes default natural sorting is not already available. 对于预定义的“不可比较”类默认自然排序尚不可用。 For our customized classes to define natural sorting then we should go for Comparable. 为了让我们的自定义类定义自然排序我们应该选择Comparable。 In case of default natural sorting compulsory object should be homogenous and Comparable otherwise we will get CCE (ClassCastException). 在默认情况下自然排序强制对象应该是同质且可比较的否则我们将获得CCE(ClassCastException)。 Example: 例 import java.util.*; class TreeSetClass { public static void main(String[] args) { Student s1 new Student(10); Student s2 new Student(30); Student s3 new Student(70); Student s4 new Student(20); // Here we are not passing Comparator object in Collection // class constructor for default sorting TreeSet ts new TreeSet(); // adding elements to TreeSet ts.add(s1); ts.add(s2); ts.add(s3); ts.add(s4); // Customized Sorted List System.out.println(Default sorting : ts); } } // Here we are implementing Comparable interface class Student implements Comparable { int code; Student(int code) { this.code code; } public String toString() { return Code - code; } // Here we are overrding compare() method of Comparable interface public int compareTo(Object obj) { int code1 this.code; Student intermediate (Student) obj; int code2 intermediate.code; if (code1 code2) return -1; else if (code1 code2) return 1; else return 0; } } Output 输出量 E:\Programsjavac TreeSetClass.java E:\Programsjava TreeSetClass Default sorting :[ Code - 10, Code - 20, Code - 30, Code - 70] 翻译自: https://www.includehelp.com/java/how-to-sort-objects-of-the-collection-in-java.aspx
http://www.yutouwan.com/news/99768/

相关文章:

  • 网站添加icp备案号wordpress做相册
  • 电子商务网站建设与运维论文烟台专业做网页的公司
  • 怎样去同行网站做外连接唐山哪家做网站好
  • 如何在各网站做推广app开发公司名字
  • 做百度百科的网站怎么自己制作小程序商城
  • ps里面怎么做网站对联广告百度下载并安装最新版
  • 做猎头可以在哪些网站注册电子商务网站课程设计总结
  • 音乐网站需求分析香烟网上商城
  • 网站管理员怎么联系自己怎么制作微信网页链接
  • 淘客网站如何做能加快收录良乡网站建设公司
  • 做外贸推广的网站正确的网线的顺序图
  • seo技术服务外包做seo是要先有网站吗
  • 做excel的网站太原住房和城乡建设部网站
  • 酒店网站建设的基本内容好看的网站ui
  • 成都网站开发 Vr网站建设第一步
  • 网站建设常用工具免费公司网站设计
  • 北京兼职做网站建设网站建设域名服务器
  • 超值高端网站设计如何做免费的网站推广
  • 上海南建设培训执业中心网站襄阳网络推广公司
  • 云南网站制作需求支付公司网站建设费账务处理
  • 哪里可以做公司网站做原型的网站
  • 猪八戒设计网站如何做兼职建设商务网站需要哪些步骤
  • 网站的关于我们怎么做wordpress运行php 404错误
  • 三拼域名做网站网站内容描述
  • 网站正在建设中 html5营销型网站建设的利与弊
  • 中国建设银行ie下载网站本地网站做不大
  • 电子商务网站建设的代码文字生成网址
  • seo怎么做网站排名微做网站
  • 河北提供网站建设公司哪家好江苏住房和城乡建设厅网站报考
  • 个人站长做网站如何做网站宣传片