Question:
In Java, what is a "collection class'?
lolzitstre
2007-02-21 20:51:57 UTC
What does the terms "collection class" mean in the world of Java programming? Please help. Thank you!
Four answers:
Innocence Redefined
2007-02-22 05:00:51 UTC
The interface that all collections implement that guarantee you can always add, remove, clear, size, iterator, contains, toArray etc. in a standard way. Don't confuse this with the Collections class. toArray can be made smarter if you pass it an empty array to fill just the right size. Then you have an array of specific classes, not just generic Objects. Use it like this:



Dogs[] dogs =( Dogs [] )dogArrayList.toArray( new Dogs[dogArrayList.size()] );

The Collection.toString method implemented by all Collections is a great debugging tool to dump out the entire contents of a Collection in a reasonably human-readable format enclosing each element in [].
Richard H
2007-02-21 21:09:24 UTC
I realize you asked about Java, and my answer isn't about that language, but this might help you.



In Visual BASIC, a collection class is a class that allows a user to have a group of simmilar objects put together. An example of this is records in a database table. How is a database table like a collection class? Let me explain.



Each RECORD in the TABLE is an OBJECT in the COLLECTION. Each FIELD in the RECORD is a PROPERTY of the OBJECT. There are certian PROPERTIES and METHODS that are not of the INDIVIDUAL RECORDS, but of the WHOLE COLLECTION - the COUNT property returns the NUMBER OF RECORDS in the TABLE. The ITEM property returns an INDIVIDUAL record. You can MoveFirst, MovePrevious, MoveNext and MoveLast to get between RECORDS.
run4ever79
2007-02-21 20:57:23 UTC
A collection is similar to the notion of the STL in C++ each collection represents a particular type of data-structure, and implements interfaces that support things like iteration.
dugans
2017-01-03 11:40:07 UTC
try including: public MusicPlayingDevice() { MusicPlayingDevice inner maximum record String musicLibrary = new ArrayList String (); inner maximum record String playList = new ArrayList String (); } interior the commonplace public precis type MusicPlayingDevice


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...