简体   繁体   中英

ArrayLists and HashMaps are recommended to use in Java?

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:-)))

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM