zl程序教程

您现在的位置是:首页 >  后端

当前栏目

java中对List中对象排序实现详解编程语言

2023-06-13 09:20:46 时间
System.out.println("id:"+news.getId()); System.out.println("title:"+news.getTitle()); System.out.println("hits:"+news.getHits());
Collections.sort(list, new Comparator News () { public int compare(News arg0, News arg1) { int hits0 = arg0.getHits(); int hits1 = arg1.getHits(); if (hits1 hits0) { return 1; } else if (hits1 == hits0) { return 0; } else { return -1; }); return list; }

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/16049.html

cjava