Of course! The method TreeMap.putAll(and the TreeMap constructor that accepts SortedMap) calls inside itself a method called buildFromSortedthat is described in the documents as: "An algorithm for constructing a linear time algorithm from sorted data", so that it sounds as if it does what you want.
Just give the method putAllsomething that implements Map, but where the map line input iterator ( Map.entrySet().iterator()) returns a list of sorted values.
source
share