Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data Structure Brushup (Java)

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?

like image 669
Daddy Warbox Avatar asked Dec 03 '08 14:12

Daddy Warbox


People also ask

What is data structure in Java?

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.

What are the data structures provided by the Java utility package?

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.

What are the data structures used for sequential data structure?

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.

What is data structures tutorial?

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.


1 Answers

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

like image 73
Andreas Petersson Avatar answered Sep 22 '22 02:09

Andreas Petersson