This sample book chapter shows how Java technology can help you accomplish the traditional data structuring needed for serious programming, and introduces you to the fundamental data structures that the standard Java library supplies.
This sample book chapter shows how Java technology can help you accomplish the traditional data structuring needed for serious programming, and introduces you to the fundamental data structures that the standard Java library supplies.
the collections are very useful.
and more useful when you realise you can put your own objects into the data structures – as long as you implement the very simple comparison funcions you can very easily use the java supplied algortihms such as sort().
The fact that primitive types are not objects requires all kinds of contortions to store them in collections. For example, take a look at java/util/Arrays.java in the JDK source. Its so bad its laughable — the sorting algorithm is duplicated once for each type of primitive array, and the only difference is the static type signature.
On the other hand, if you use collections instead of primitive arrays, another problem comes into play: wasted memory due to boxing overhead.
In Common Lisp, everything is an object, even numbers. Furthermore, you can allocate so-called “specialized arrays”, which behave exactly like normal arrays, except they can only hold one type, and hold it efficiently. For example a specialized array of floats behaves like a high level collection, but is very memory efficient.
Yes, but CLISP is never going to have the widespread usage of Java. (And(I am very glad of)that)!
first of all, i cant remember the last time i used an array, let alone an array of primitives. so for us its a non-issue, our app is full of ArrayLists of container beans.
Depends on what kind of work you do. I for one can’t remember the last time I had to rely on a collection of primitives, but I work with multidimensional arrays of primitives daily.
yeah, this is true. im not saying that primitive/object relationships couldnt have been handled better, but i wouldnt say its a critical flaw, at least to most people.
and boxing does give you some overhead, but how bad is it? its another few bytes
and correct me if im wrong, but couldnt you implement the functionality your talking about by writing your own? extend AbstractList, and make your own specialized collections? if the only problem is the lack of polymorphism for primitives, then an IntArrayList shouldnt be too hard.