What are collections for? Lists, queues, sets?
What can be stored in them?
Can you please give references of examples of working with collections?
What are collections for? Lists, queues, sets?
What can be stored in them?
Can you please give references of examples of working with collections?
Something the previous speaker’s response is too short for my taste. And the article for my taste is not the most "tasty."
What are collections for? > lists, queues, and sets?
Very simple - in collections you can store objects, almost any. Collections, in one way or another, are dynamic arrays, that is, an array that increases in length when you write a new object. For example, let you write some image handler. You certainly do not know how many snapshots will come to your storage. Maybe zero, maybe a hundred. You create a dynamic ArrayList list and store what you need in it.
The priority queue is often used to sort an array and to find the maximum / minimum.
A set is an ordered set. Set collections are designed to store a variety of non-duplicate objects. Thus, when adding two elements with the same value to the collection, with the Set interface, the collections will be perceived as one element. Each object that you add to the set collection will receive its own unique hash code, that is, the string by which it will be possible to access it. An example of using Set - let you write a database of car numbers. There is not a situation where two cars have one number. It is the set of speed of work (search and add) in this regard will be more effective than other data structures.
What can be stored in them (and how? Examples)?
About how to store. I gave something similar to the answer in another question .
If you want to save time in studying the issue with the collections, I highly recommend to look at the examples in screencast format on YouTube. IMHO is a great practical exercises for everyone. I liked this most about collections:
https://www.youtube.com/watch?v=gBaei16Yy4s (and after five lessons)
By the way, I must say that these are not the only good lessons on the collections on youtube, there are still a lot of not bad ones.
Ps . If the material seems to be incomplete, you can ask additional questions, such as examples of work with each specific collection. For in one answer it is rather difficult to clarify everything briefly.
Source: https://ru.stackoverflow.com/questions/583902/
All Articles