草庐IT

java - TreeMap lastKey 查找时间

SortedMap接口(interface)的TreeMap.lastKey()部分的时间复杂度是多少?oracle文档提到了有关TreeMaps的内容:Thisimplementationprovidesguaranteedlog(n)timecostforthecontainsKey,get,putandremoveoperations. 最佳答案 根据OpenJDK中的实现,是O(logN):publicKlastKey(){returnkey(getLastEntry());}finalEntrygetLastEntry()