我有这样的树状图:的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中有任何索引 –