[英]HashMap: sorting key into alphabetical order with it's mapped values
我之前在這里問過一個問題,已解決,但現在我遇到了另一個問題。
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
也可能是有益的,它只需要一個鍵並對其自動排序。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.