In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
本篇内容主要讲解"java List常见操作有哪些",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"java List常见操作有哪些"吧!
迭代器Iterator ite = resultList.iterator();while (ite.hasNext()) { Map result = ite.next(); ite.remove();}排序Collections.sort(userInfoList, new Comparator() { public int compare(Map o1, Map o2) { return ((Date) o1.get("createTime")).compareTo((Date) o2.get("createTime")); }});Collections.sort(downList, new Comparator() { @Override public int compare(Map o1, Map o2) { String timeStr1 = ObjectUtil.objToString(o1.get("statDate")); String timeStr2 = ObjectUtil.objToString(o2.get("statDate")); timeStr1 = timeStr1.replaceAll("(?:年|月)", ""); timeStr2 = timeStr2.replaceAll("(?:年|月)", ""); Integer yearMonth2 = Integer.valueOf("".equals(timeStr1) ? "0" : timeStr1); Integer yearMonth3 = Integer.valueOf("".equals(timeStr2) ? "0" : timeStr2); return yearMonth2 > yearMonth3 ? -1 : 1; }});去重Set setMap = new HashSet(); for (int i = 0; i < md5s.size(); i++ ) { tempList = scenesDomain.queryScenAppList(rootScenId, null, md5s.get(i), crowdDates.get(i), Constants.QUERYAPPBYSCENID_TOPSIZE); for (Map map : tempList) { if (setMap.add(map)) { appList.add(map); } } }中文排序public static void main(String[] args) { ArrayList list = new ArrayList(); list.add("一鸣惊人-Y"); list.add("人山人海-R"); list.add("海阔天空-H"); list.add("空前绝后-K"); list.add("后来居上-H"); Comparator cmp = Collator.getInstance(java.util.Locale.CHINA); Collections.sort(list, cmp); for (String str : list) { System.out.println(str); }}实体类排序import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.List;public class SortUser { public static void main(String[] args) { List userlist = new ArrayList(); userlist.add(new User("H - 哈哈 ", 32)); userlist.add(new User("O - 噢哈哈", 22)); userlist.add(new User("W - 哇哈哈", 22)); Collections.sort(userlist, new Comparator() { @Override public int compare(User u1, User u2) { // 先按年龄排序 int flag = u1.getAge().compareTo(u2.getAge()); // 年龄相等比较姓名 if (flag == 0) { return u1.getName().compareTo(u2.getName()); } else { return flag; } } }); for (User user : userlist) { System.out.println(user.getName()); } }}class User { private String name; private Integer age; public User(String name, Integer age) { 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; }}到此,相信大家对"java List常见操作有哪些"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.