gpt4 book ai didi

java - HashMap : sorting key into alphabetical order with it's mapped values

转载 作者:行者123 更新时间:2023-12-01 23:04:45 25 4
gpt4 key购买 nike

我不久前在这里问了一个问题,解决了它,但现在我遇到了另一个问题。

This is jumblesOrdered ArrayList: [act, opst, dgo, art, aprt, fgor]
This is jumbles ArrayList: [atc, otsp, gdo, atr, arpt, grof]

This is dictionaryOrdered ArrayList: [act, act, act, dgo, dgo, opst, opst, opst, opst, opst, opst, art, art, art, aprt, aprt, aprt, fglo, fglo, fgor, gopr, glos]
This is dictionary ArrayList: [act, cat, tac, dog, god, post, pots, stop, spot, tops, opts, rat, tar, art, trap, tarp, part, flog, golf, frog, gorp, slog]

This is jumbleWordHM: {opst=otsp, art=atr, fgor=grof, aprt=arpt, dgo=gdo, act=atc}
This is dictWordHM: {opst=post pots stop spot tops opts, art=rat tar art, glos=slog, gopr=gorp, fgor=frog, aprt=trap tarp part, dgo=dog god, act=act cat tac, fglo=flog golf}Current Output:
<小时/>

当前输出:

atc act cat tac
otsp post pots stop spot tops opts
gdo dog god
atr rat tar art
arpt trap tarp part
grof frog

期望的输出:

arpt part tarp trap
atc act cat tac
atr art rat tar
gdo dog god
grof frog
otsp opts post pots spot stop tops
<小时/>

我的用于打印当前输出的代码:

    for (int i = 0; i < jumblesOrdered.size(); i++) {
String wordAnswer = jumblesOrdered.get(i);
System.out.println(jumbles.get(i) + " " + dictWordHM.get(wordAnswer));

}

每行的第一个单词是打乱的单词,后面的单词是可以由打乱的字母组成的字典单词。

我唯一的问题是我想将打乱的单词按字母顺序组织,例如:

arpt - dictionary words
atc - dictionary words
atr - dictionary words
etc.....

最佳答案

HashMap 无法排序,您应该使用某种排序映射,例如 TreeMap,但映射只能按键排序。 (TreeSet 也可能是有益的,它只需要一个键并自动对它们进行排序。)

关于java - HashMap : sorting key into alphabetical order with it's mapped values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22977225/

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