您好,登錄后才能下訂單哦!
本篇內容主要講解“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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。