• String类型转List<Integer>


    public static void main(String[] args) {
            String a ="1,2,3,4,5";
            List<Integer> integers = stringToList(a);
            integers.forEach(s-> System.out.println(s));
        }
    
    
    //String   转 List<Integer>
    private static List<Integer> stringToList(String strs){
            String[] a= strs.split(",");
            int[] array = Arrays.stream(a).mapToInt(Integer::parseInt).sorted().toArray();
            List<Integer> listx = Arrays.stream(array).boxed().collect(Collectors.toList());
            return listx;
        }
    List<T> list=JSONArray.parseArray("",T.class);
    其中T为要转为的list其中的对象,比如创建的实体类。
    //  String 转list
    private List<String> stringToList(String strs){
      String str[] = strs.split(",");
       return Arrays.asList(str);
    }

    // List<IdAndNameDto> 转 Map<Integer,List<String>>
    Map<Integer, List<String>> storeNameMap = baiShiOrderNo
    .stream()
    .collect(Collectors.toMap(IdAndNameDto::getId,x->{
    List<String> list = new ArrayList<>();
    list.add(x.getName());
    return list;
    },(item1, item2) ->{
    item1.addAll(item2);
    return item1;
    }));
     





        /** 对list分组. */
        public static <K extends Comparable, V> TreeMap<K, List<V>> groupAndSort(
                List<V> list, Function<V, K> groupFunction) {
            TreeMap<K, List<V>> map = Maps.newTreeMap();
            if (list == null || list.isEmpty()) {
                return map;
            }
    
            for (V v : list) {
                if (v == null) {
                    continue;
                }
    
                K k = groupFunction.apply(v);
                if (k == null) {
                    continue;
                }
    
                List<V> groupList = map.get(k);
                if (groupList == null) {
                    groupList = Lists.newLinkedList();
                    map.put(k, groupList);
                }
    
                groupList.add(v);
            }
    
            return map;
        }
    
        //list转map
        TreeMap<Integer, List<UserProfileWedplanner>> rawMap =
                MijMap.groupAndSort(rawList, UserProfileWedplanner::getDataTypeCode);
    
    // String 转 转实体类
    String a ="{"traceLogs":[{"mailNo":"50634526168078","traces":{"trace":[{"acceptAddress":"北京市","acceptTime":"2013-12-31 22:41:47","remark":"北京市【中关村软件园分部】,【中关村软件园分部-客服/0000】已揽收","scanType":"收件"},{"acceptAddress":"北京市","acceptTime":"2014-01-01 02:24:24","remark":"到北京市【北京转运中心】","scanType":"到件"},{"acceptAddress":"北京市","acceptTime":"2014-01-01 13:24:59","remark":"北京市【北京转运中心】,正发往【潍坊转运中心】","scanType":"发件"},{"acceptAddress":"潍坊市","acceptTime":"2014-01-01 21:42:31","remark":"到潍坊市【潍坊转运中心】","scanType":"到件"},{"acceptAddress":"潍坊市","acceptTime":"2014-01-02 02:47:05","remark":"潍坊市【潍坊转运中心】,正发往【滨州】","scanType":"发件"},{"acceptAddress":"滨州市","acceptTime":"2014-01-02 08:22:48","remark":"到滨州市【滨州】","scanType":"到件"},{"acceptAddress":"滨州市","acceptTime":"2014-01-02 18:47:06","remark":"滨州市【滨州】,字草 已签收","scanType":"签收"}]},"check":false,"problems":{"problem":[{"seqNum":1,"problemCause":"请提供一个可联系的电话","noticeSite":"中关村软件园分部","problemType":"联系不上收件人","registerMan":"系统管理员","registerDate":"2017-01-11 16:31:19","registerSite":"西湖一部"}]}}]}";
    //jsonArray 转成数组
    //JSONArray pdfArray = JSONArray.parseArray(a);
    //获取数组下标为0的 //String pdfArrayOne = pdfArray.getString(0); BaiShiOrderPrintVo pdf = JSONObject.parseObject(a, BaiShiOrderPrintVo.class);

    //String 转实体类
    private PpsPdfInfoConstants conversionPdfInfo(String pdfInfo) {
    JSONArray pdfArray = JSONArray.parseArray(pdfInfo);
    String pdfArrayOne = pdfArray.getString(0);
    JSONArray jsonArray = JSONObject.parseObject(pdfArrayOne, JSONArray.class);
    String jsonData = jsonArray.getString(0);
    PpsPdfInfoConstants pdf = JSONObject.parseObject(jsonData, PpsPdfInfoConstants.class);
    return pdf;
    }

      

      

  • 相关阅读:
    Oracle函数如何把符串装换为小写的格式
    Oralce中的synonym同义词
    JS中getYear()的兼容问题
    How to do SSH Tunneling (Port Forwarding)
    所谓深度链接(Deep linking)
    upload size of asp.net
    发一个自动刷网站PV流量的小工具
    解决Visual Studio 2008 下,打开.dbml(LINQ) 文件时,提示"The operation could not be completed." 的问题。
    在资源管理器中使鼠标右键增加一个命令,运行cmd,同时使得当前路径为资源管理器当前的目录
    使用SQL语句获取Sql Server数据库的版本
  • 原文地址:https://www.cnblogs.com/chuan-yoyo/p/15293791.html
Copyright © 2020-2023  润新知