//1.得到日期 LocalDate localDate = LocalDate.now(); //輸出 yyyy-mm-dd System.out.println(localDate.toString()); //獲取今天是今年的第幾天 System.out.println(localDate.getDayOfYear()); //第幾月 System.out.println(localDate.getMonthValue()); //第幾天 System.out.println(localDate.getDayOfWeek().getValue()); //2.便利User List<User> mapList = new ArrayList<>(); //添加數據 for (int i = 0; i < 10; i++) { User user = new User(); user.setId((int) (Math.random()*100)); user.setName("name" + i); mapList.add(user); } //根據id升序排序 mapList.sort((s1,s2)-> s1.getId().compareTo(s2.getId())); //獲取user對象裏面的id返回到indexList裏面 List<Integer> indexList = mapList.stream() .map(User::getId).collect(Collectors.toList()); //copy對象 List<User> newMapList = mapList.stream() .map(oldUser -> { User newUser = new User(); BeanUtils.copyProperties(oldUser, newUser); return newUser; }).collect(Collectors.toList()); //數組轉List List<String> arrayToList = Arrays.asList("1","3","2","3"); List<String> delRepetList = new ArrayList(); for (int i = 0; i < 5; i++) { delRepetList.add(String.valueOf(i/2)); } //去重複 Set s = new HashSet(delRepetList); delRepetList.clear(); delRepetList.addAll(s); //list數據篩選 List<Record> recEditorArticleList = paramList.stream().filter(x->x.get("type").equals("rec")).collect(Collectors.toList());
本文同步分享在 博客「DencyCheng」(CSDN)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。java