Alphabetically sort ArrayList<String> or HashMap<String, x>?


Is there a way to sort an ArrayList<String> or a HashMap<String, x> built into those classes? I can do it myself manually, but was wondering if anything exists to do it for you. For example, in C++, a map<string, x> automatically sorts itself alphabetically.

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

CPColinConnect With a Mentor Senior Java ArchitectCommented:
java.util.Collections.sort() takes a List as its parameter and sorts it in-place.

java.util.TreeMap implements SortedMap (and Map, like HashMap), and keeps its keys in sorted order.
All Courses

From novice to tech pro — start learning today.