Reputation: 1715
Im coming from Perl where Hashes and Arrays are comfortable to use since they are very dynamical and do lots of stuff in the background which usually would annoy the programmer.
Similar to this i start to use hashmaps and ArrayLists since they make the programming work a litte bit easier and faster. But how is the perfomance? Is it recommended to use these types of data for larger projects or should i only limit myself to the core of Java with strings and arrays?
Thanks for all answers:-)))
Upvotes: 1
Views: 108
Reputation: 8815
If you have unchanging data that you will write to once (or few times) and read many times, an array may be (very slightly) faster than an ArrayList
. An array might also consume (marginally) less memory than an ArrayList
. However, ArrayList
in particular is a class used very often so it is useful to be able to work with it (and more generally with other classes that implement the List
interface), and underneath it, the elements are stored in an array so accesses should not really be slower.
HashMap
s implement a hashing-based map. They are typically an O(1)
access data structure and implementation so they are indeed recommendable. As a class implementing the Map
interface, they are also a useful way of mapping one object to another, which is a commonly encountered problem.
Most Collections
classes (and interfaces) are well designed and easy to use.
Upvotes: 1
Reputation: 41168
HashMap
, ArrayList
, etc are part of the core Java libraries and are recommended for use.
You should investigate the other Collection
s as well though, since depending on what you are doing some of the other options may be even better for you.
Upvotes: 1