From: Robert Klemme Date: 2006-05-26T00:25:18+09:00 Subject: Re: Equivalent of collections in Java 2006/5/25, Ryan Leavengood : > On 5/25/06, Krekna Mektek wrote: > At the most abstract level every programming language needs some form > of "collections" in the sense of data structures used to contain > information. In Ruby there is Array and Hash classes, which can handle > most of what the core Java Collection classes can handle. The > statically typed nature of Java requires such a huge variety of > classes, whereas Ruby gets much of the same functionality with just > two classes. The static typing of Java is *not* responsible for the comparatively large number of collection classes. All Java collections are based on Object as element type which is as generic as it can get without generics. Java collections indeed offer more *functionality*: these are the collection types which do not have an equivalent in Ruby's std lib: TreeSet, TreeMap, LinkedList, IdentityHashMap, Stack and the synchronized Collections Vector and Hashtable. > One benefit of the Java libraries is you can get very specific about > what type of data structure you want to use, even taking into account > the internal representation. For example you can choose to use an > ArrayList or a LinkedList depending on which style of list would be > the most efficient for your needs. Some might argue this is against > the spirit of OO since it exposes the internal representation of the > data structure. That's not against OO at all. All classes have certain characteristics - algorithmic complexity being one of them. It's perfectly valid to have several implementations of the same concept (aka interface) from which a developer can pick the most appropriate for the solution he wants to build. In fact, OO usually makes exchanging one implementation for another much easier through inheritance (duck typing in Ruby). > Either way in the case of Ruby core classes, you just have Array and Hash. You could add to that Set and Queue (thread safe) which come with the std distribution. Kind regards robert -- Have a look: http://www.flickr.com/photos/fussel-foto/