Converting ArrayList of Characters to a String?

前端 未结 11 2128
清歌不尽
清歌不尽 2020-12-05 13:39

How to convert an ArrayList to a String in Java? The toString method returns it as [a,b,c] string - I wa

11条回答
  •  攒了一身酷
    2020-12-05 13:45

     private void countChar() throws IOException {
        HashMap hashMap = new HashMap();
        List list = new ArrayList();
        list = "aammit".chars().mapToObj(r -> (char) r).collect(Collectors.toList());
        list.stream().forEach(e -> {
            hashMap.computeIfPresent(e, (K, V) -> (int) V + 1);
            hashMap.computeIfAbsent(e, (V) -> 1);
        });
    
        System.out.println(hashMap);
    
    }
    

提交回复
热议问题