Important Web Design and Development Short Questions
Chapter: 6
Question 1:
How do Java collections store objects?
Answer:
Java collections store references to objects, similar to using a void* in C.
Chapter: 6
Question 2:
What method is used to add an element to a Java collection?
Answer:
The add(Object) method is used to add an element to a collection.
Chapter: 6
Question 3:
What does the isEmpty() method do in a Java collection?
Answer:
The isEmpty() method returns true if the collection contains no elements, otherwise false.
Chapter: 6
Question 4:
How does the remove(Object) method work in a Java collection?
Answer:
The remove(Object) method removes a single instance of the specified element from the collection if it is present.
Chapter: 6
Question 5:
What is the ArrayList in Java?
Answer:
ArrayList is a resizable array in Java that grows or shrinks as elements are added or removed.
Chapter: 6
Question 6:
How can you retrieve an element from an ArrayList by its position?
Answer:
Use the get(int index) method to retrieve an element at the specified position.
Chapter: 6
Question 7:
What does the remove(int index) method do in an ArrayList?
Answer:
The remove(int index) method removes the element at the specified position and shifts any subsequent elements to the left.
Chapter: 6
Question 8:
How does a HashMap store elements?
Answer:
A HashMap stores elements in the form of key-value pairs, where keys are unique.
Chapter: 6
Question 9:
What method is used to associate a value with a key in a HashMap?
Answer:
The put(Object key, Object value) method is used to associate a value with a key.
Chapter: 6
Question 10:
How can you retrieve a value from a HashMap using its key?
Answer:
Use the get(Object key) method to retrieve the value associated with a specific key.