我有這樣的樹狀圖:的Java TreeMap的返回鍵位置
Map teamNameAndLeague = new TreeMap();
teamNameAndLeague.put("team1", "name1");
teamNameAndLeague.put("team2", "name2");
teamNameAndLeague.put("team3", "name3");
我如何可以搜索鍵和返回鍵實例的指標:
search for key: "team1" in teamNameAndLeague, Returns index: 1
我有這樣的:
int indexWin = new ArrayList<String>(teamNameAndLeague.values()).indexOf("name2") + 1;
That returns: 2
它返回此密鑰的索引,但是用於搜索密鑰值。我怎麼能做出類似的東西,而不是尋找鑰匙
它返回的索引基於關鍵...是不是搜索關鍵? – redFIVE
你的索引是依賴於插入順序還是根據TreeMap?我不認爲在TreeMap中有任何索引 –