gpt4 book ai didi

java - 将树形图键和值转换为数组

转载 作者:行者123 更新时间:2023-12-02 00:32:51 25 4
gpt4 key购买 nike

我需要将 TreeMap 转换为数组;谁能告诉我这是怎么做的?我需要键和值。我将每个单词映射到文本文件中的频率

这是输出:

Bypass Internet Censorship.txt

{about=1, administrators=1, ago=1, and=1, around=1, asking=1, at=2, blocked=1, by=1, com=1, device=1, either=1, filtering=1, freerk=1, get=1, helps=1, hope=1, i=1, long=1, not=1, or=2, remember=1, school=1, sites=1, so=1, some=1, someone=1, that=1, the=1, this=1, to=1, view=1, was=1, ways=1, web=1, were=1, work=1, www=1, zensur=1}

最佳答案

    StringBuilder temp=new StringBuilder();

for(Map.Entry<String,Integer> entry : treeMap.entrySet())
{
String key = entry.getKey();
Integer value = entry.getValue();

temp.append(key).append(" = ").append(value).append(", ");
}

//TODO remove the last comma

String result=temp.toString();

关于java - 将树形图键和值转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8559449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com