Collections and Generics Flashcards
What is a collection?
An object that can hold other objects
What a set?
collection that is unordered
What is a list?
collection that is ordered in some way, and doesnt require that its elements be unique
Whats a Map?
Elements in the collections have key, value pairs
T/F: Collections store objects, and cannot store primitive types?
True. Wrapper classes must be used for primitive types
Common collection classes
pic
Whats an arraylist compared to an array?
its size can be expanded and efficient for accessing elements randomly
whats a linkedlist
similar to arraylist but with more features. Its elements are linked to other elements.
To add or remove, just
whats a hashmap?
stores object with key-value pairs
whats a treemap?
stores objects having key-value pairs in a special tree structure
What are generics?
class type that takes the data types as parameters. Makes it closer to dynamically typed language
Explain arrayList constructors
ArrayList<Type>()
ArrayList<Type>( int n)
ArrayList<Type>(Collection obj)</Type></Type></Type>
Defaults to size 10
ArrayList methods
Lot more functionality than array
linkedlist
Whats the difference in adding element to top of LinkedList vs ArrayList?
ArrayList stored in contiguous elements so adding to top, bumps all down one.
LinkedList just changes reference of the top…. not totally sure but its more efficient