【发布时间】:2018-12-20 04:44:16
【问题描述】:
我最初有一个字符串数组列表,但我想将其保存为这些字符串的数组列表。toCharArray()。是否可以制作一个存储 char 数组的数组列表?这是我尝试实现它的方法。
String[] words = new String[]{"peter","month","tweet", "pete", "twee", "pet", "et"};
HashMap<Integer,ArrayList<Character[]>> ordered = new HashMap<>();
int length = 0;
int max = 0; //max Length of words left
for(String word: words){
if(ordered.containsKey(length) == false){ //if int length key doesnt exist yet
ordered.put(length, new ArrayList<Character[]>()); //put key in hashmap with value of arraylist with the one value
ordered.get(length).add(word.toCharArray());
}
}
【问题讨论】:
标签: java arrays string arraylist char