What is the need for a collection structure in java?

What is the need for a Java collection structure, since all data operations (sorting / adding / deleting) are possible using arrays, and in addition, the array is suitable for memory consumption, and performance is also better than collections.

Can someone point me to a real-time data-oriented example that shows the difference in both (array / collections) of these implementations.

+6
source share
10 answers
  • Arrays do not change.
  • Java Collections Framework , ( ), (, Vector, ), - , - (, Hashtable, ).
  • Java Collections Framework , List, , ; / Map, - -.

, Java Collections Framework , .

+26

:

  • Java- , .
  • . (. ArrayList) .
  • (, -) . HashMap .
  • , : ArrayList LinkedList, HashMap TreeMap, ..
  • , : - , . .

, :

  String[] strings = new String[10];
  Object[] objects = strings;

  objects[0] = new Date();  // <- ArrayStoreException: java.util.Date
+6

, Set, List Map, " ". / .

+2

API . .

LinkedList: , . .

Set: , - O (N). HashSet O (1).

. , , .

+1

. , :

  • HashSet
  • ArrayList
  • HashMap
  • TreeSet
  • TreeMap
  • LinkedList

, , /, , , Hash * . , .

0

, "", Java Dictionary, , ...

, , , . , List ( Set) Map .

, , List Set , . , " " .

, , , , . , , , , .

- .

, , , , , . ..

, /, , .length , . , , , . .

0

- Java, , , , , , , , , , , , , , , , . , ArrayList, .

- , , , , , LinkedList, , , , , . .

0

Java , .

, ARRAY , , , - .

, , :

.

:

  • - .
    / ; (.. , ).

    . , " ", .

  • Set - " " - , , , .

    - , , . -;
    - , . " ", " ?", " ?" .

:

0

, , , , .

:

  • ArrayList - , , .
  • LinkedList - (FIFO) (LIFO).
  • HashSet - , . HashSet .
  • TreeSet - TreeSet - , .
  • ArrayDeque - " - " (FIFO) " - " (LIFO).
  • HashMap - HashMap -, .
  • Treemap - TreeMap stores key-value pairs in sorted ascending order, and the speed of extracting an element from TreeMap is quite high.

To learn more about Java collections, check out this article .

0
source

All Articles