| 1234567891011121314151617181920212223242526272829303132 |
- package com.zd.system.api;
- import cn.hutool.core.util.NumberUtil;
- import java.util.*;
- import java.util.stream.Collectors;
- public class test {
- public static void main(String[] args) {
- String[] urlStr = new String[5];
- urlStr[0] = "15-31-17.mp4";
- urlStr[1] = "15-31-29.mp4";
- urlStr[2] = "15-31-20.mp4";
- urlStr[3] = "15-31-30.mp4";
- urlStr[4] = "15-31-15.mp4";
- List<Map<String,Object>> collect = Arrays.asList(urlStr).stream()
- .map(a -> {
- Map<String,Object> urlMap = new HashMap<String,Object>();
- Integer value = Integer.parseInt(a.substring(0, a.lastIndexOf(".")).replaceAll("-", ""));
- urlMap.put("key",value);
- urlMap.put("value",a);
- return urlMap;
- }).collect(Collectors.toList());
- Map<String,Object> arrMap = Optional.ofNullable(collect).orElseGet(Collections::emptyList)
- .stream()
- .sorted((c, d) -> NumberUtil.compare(Integer.parseInt(d.get("key").toString()),Integer.parseInt(c.get("key").toString())))
- .collect(Collectors.toList()).get(0);
- System.out.println(arrMap.get("value"));
- }
- }
|