本篇内容主要讲解“java List常见操作有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“java List常见操作有哪些”吧!
Iterator<Map<String, Object>> ite = resultList.iterator(); while (ite.hasNext()) { Map<String, Object> result = ite.next(); ite.remove(); }
Collections.sort(userInfoList, new Comparator<Map<String, Object>>() { public int compare(Map<String, Object> o1, Map<String, Object> o2) { return ((Date) o1.get("createTime")).compareTo((Date) o2.get("createTime")); } }); Collections.sort(downList, new Comparator<Map<String, Object>>() { @Override public int compare(Map<String, Object> o1, Map<String, Object> 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<Map<String, Object>> setMap = new HashSet<Map<String, Object>>(); for (int i = 0; i < md5s.size(); i++ ) { tempList = scenesDomain.queryScenAppList(rootScenId, null, md5s.get(i), crowdDates.get(i), Constants.QUERYAPPBYSCENID_TOPSIZE); for (Map<String, Object> map : tempList) { if (setMap.add(map)) { appList.add(map); } } }
public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("一鸣惊人-Y"); list.add("人山人海-R"); list.add("海阔天空-H"); list.add("空前绝后-K"); list.add("后来居上-H"); Comparator<Object> 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<User> userlist = new ArrayList<User>(); userlist.add(new User("H - 哈哈 ", 32)); userlist.add(new User("O - 噢哈哈", 22)); userlist.add(new User("W - 哇哈哈", 22)); Collections.sort(userlist, new Comparator<User>() { @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常见操作有哪些”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。