This should be easy for many of you, but for me it's just another bit of rust needing to be chipped away as I get back into basic Java coding. Using bloody associative arrays for so long in other languages have turned me nice and spoiled. :P
My problem is simple: I'm storing a set of objects, each containing a string and a number, in a list. I would like each object inserted into this list to be sorted alphabetically by its string. I would also like to be able to retrieve objects from the list by their string as well. I would like to do this as formally and/or efficiently as possible.
Is there something already available in the Java standard libraries for this?
Data structure can be defined as a collection of different data elements. Data structure in Java is a way of storing and organizing data and information in a computer system so that the stored data can be retrieved and utilized efficiently.
The data structures provided by the Java utility package are very powerful and perform a wide range of functions. These data structures consist of the following interface and classes −. Enumeration. BitSet. Vector. Stack. Dictionary. Hashtable. Properties.
The arrangement of data in a sequential manner is known as a linear data structure. The data structures used for this purpose are Arrays, Linked list, Stacks, and Queues. In these data structures, one element is connected to only one another element in a linear form.
Data Structures Tutorial. Data Structures (DS) tutorial provides basic and advanced concepts of Data Structure. Our Data Structure tutorial is designed for beginners and professionals. Data Structure is a way to store and organize data so that it can be used efficiently.
there is a great writeup on java collections which covers most of your needs.
short advice concerning this: use a TreeMap(Comparator c) with a custom Comparator. key ist the string, value is the composite object with string and number
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With