Java Homework Collection Operations - Exercises

1. Multiple-choice questions (7 questions in total, 31.5 points)

1. (Multiple choice question) Which of List, Set and Map inherits from the Collection interface, the following statement is correct ()

  • A. List Map
  • B. Set Map
  • C. List Set
  • D. List Map Set

My answer:  ACorrect answer:  C

0 points

2. (Multiple choice)

To construct an instance of the ArrayList class, which of the following statements is correct ( )?

  • A. ArrayList myList=new Object ();
  • B. List myList=new ArrayList ();
  • C. ArrayList myList=new List ();
  • D. List myList=new List ();

My answer:  B Correct answer:  B

4.5 points

3. (Multiple choice) Regarding the Map collection, which of the following statements is incorrect ( )

  • A. Keys must be unique
  • B. A key can only correspond to one value
  • C. Different keys can correspond to the same value
  • D. The key must be a primitive type or String type

My answer:  D Correct answer:  D

4.5 points

4. (Multiple choice) Class B inherits from class A, the collection List<A>, when adding B type objects to the collection ( )

  • A. Compile-time errors
  • B. Runtime errors
  • C. Warning
  • D. Error free

My answer:  D Correct answer:  D

4.5 points

5. (Multiple choice) Regarding the collection type constant, which of the following statements is correct ( )

  • A. The collection structure cannot be changed. i.e. elements cannot be added/removed
  • B. The element objects in the collection cannot be changed. i.e. the element cannot be replaced
  • C. Unable to change the data encapsulated in the element object in the collection
  • D. The reference to the collection type constant cannot be changed. i.e. cannot reference another collection object

My answer:  D Correct answer:  D

4.5 points

Answer analysis:

6. (Multiple choice) The following methods are not available in the Set collection ( )

  • A. add()
  • B. size()
  • C. get()
  • D. clear()

My answer:  C Correct answer:  C

4.5 points

7. (Multiple choice) Correctly declare an integer collection variable

  • A. List<int> list;
  • B. List<Integer> list;
  • C. List list<int>;
  • D. List list<T>;

My answer:  B Correct answer:  B

4.5 points

2. True or false (15 questions in total, 68.5 points)

8. (True or False)

Duplicate objects cannot be added to the ArrayList collection.

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

4.5 points

9. (True or False) If class A inherits from class B, the variable List<A> list1 collection allows adding objects of class B

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

4.5 points

10. (True or False) Adding duplicate elements to the Set collection will throw an exception

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

4.5 points

11. (True or False) Neither Set nor Map provide operations based on index positions

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  yes

0 points

12. (True or False) After the element object is removed from the collection, it will be destroyed

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

4.5 points

13. (True or False) An object cannot be placed in two collections at the same time

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

4.5 points

14. (True or False) LinkedList is an implementation class of a linked list-based List type that inherits from the Collection interface

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  yes

0 points

15. (True or False) Map can obtain the element at the specified position through the index

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

4.5 points

Answer analysis: Map has no index

16. (True or False) The keys in Map must be of basic data types

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

4.5 points

17. (True or False) Adding duplicate elements to the Set collection will throw an exception

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

4.5 points

18. (True or False) The set collection is characterized by no repetition of elements

  • A. Yes
  • B. wrong

My answer:  yes Correct answer:  yes

4.5 points

19. (True or False) Set collection does not support foreach loop statement

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

4.5 points

20. (True or False) The Set collection does not provide operations based on index positions

  • A. Yes
  • B. wrong

My answer:  yes Correct answer:  yes

4.5 points

21. (True or False) Iterator is an iterative interface that supports iterating over elements in a collection

  • A. Yes
  • B. wrong

My answer:  yes Correct answer:  yes

4.5 points

22. (True or False) The pre() method in Iterator can move the cursor forward one place

  • A. Yes
  • B. wrong

My answer:  wrong Correct answer:  wrong

5.5 points

Guess you like

Origin blog.csdn.net/qq_56350439/article/details/124434515