How to obtain index of a given LinkedHashSet element without iteration?

后端 未结 8 1639
無奈伤痛
無奈伤痛 2020-12-14 16:45

Is it even possible?

Say you have

private Set names = new LinkedHashSet();

and Strings ar

8条回答
  •  执念已碎
    2020-12-14 17:00

    Although not as efficient for the machine, this achieves it in one line:

    int index = new ArrayList(names).indexOf("John");
    

提交回复
热议问题