which data structure is best to choose regarding memory usage in java

i have been searching lately on google to see which data structure is efficient to use which will take less memory and will work fast with less complexity. any thoughts? i know map is the best if you have to search it faster through a key and arraylist does not have random access which means it is slow in searching. any other thoughts?

[344 byte] By [lrngjavaa] at [2007-11-27 6:47:49]
# 1
depends on the situation.
achyuthba at 2007-7-12 18:20:53 > top of Java-index,Java Essentials,Java Programming...
# 2
You can find plenty out about the Collections framework, their implementations and algorithms etc [url= http://java.sun.com/docs/books/tutorial/collections/index.html]here[/url]
_helloWorld_a at 2007-7-12 18:20:53 > top of Java-index,Java Essentials,Java Programming...
# 3
> depends on the situation.Yep, some are better for searching, inserting etc. There is quite a lot to consider.
_helloWorld_a at 2007-7-12 18:20:53 > top of Java-index,Java Essentials,Java Programming...
# 4
> ... arraylist does not have random access huh?what is your definition of random access?
tschodta at 2007-7-12 18:20:53 > top of Java-index,Java Essentials,Java Programming...
# 5
arraylist allows random access. sorry this is what i mean to say.
lrngjavaa at 2007-7-12 18:20:53 > top of Java-index,Java Essentials,Java Programming...
# 6

Just to make the complex question even more complex:

You may consider one or more arrays. Rather space efficient if you fill them, and you have efficient random access.

You may consider storing your data in a relational database. There are lots of built-in searching and sorting opportunities in SQL.

First and last, I agree with what's ben said: It all depends on your situation, your requirements, frequency of insertion, types of searches and a lot more. In many situations (but possibly not yours), writing a clear and easily maintainable program is more important than space and time considerations.

Message was edited by:

OleVV

OleVVa at 2007-7-12 18:20:53 > top of Java-index,Java Essentials,Java Programming...