back

The Collections framework in Java

by Lilit Kocharyan for IT, Technology 264 Comments
The Collections framework in Java

Today’s topic is a little bit technical as it is related to Java developers. We are going to speak about Java and its frameworks like Collections, the Map interface, Java TreeMap class, etc. Our team continues to study interesting and essential features in web and mobile development, so let’s continue!

Basic concepts

Collections in java is a framework that provides an architecture to store and manipulate the group of objects. The Java Collection Framework is divided into two interfaces: Collection and Map. These interfaces isolate all collections that enter the two types of data boxes: simple sets of elements and sets of “key”. Java Collection simply means a single unit of objects. Java Collection framework provides many interfaces (Set, List, Queue, Deque etc.) and classes (ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet, TreeSet etc).

Methods of Collection interface
    1. boolean add(Object element) is used to insert an element in this collection.
    2. boolean addAll(Collection c) is used to insert the specified collection elements in the invoking collection.
    3. boolean remove(Object element) is used to delete an element from this collection.
    4. boolean removeAll(Collection c) is used to delete all the elements of specified collection from the invoking collection.
    5. boolean retainAll(Collection c) is used to delete all the elements of invoking collection except the specified collection.
    6. int size() return the total number of elements in the collection.
    7. void clear() removes the total no of element from the collection.
    8. boolean contains(Object element) is used to search an element.
    9. boolean containsAll(Collection c) is used to search the specified collection in this collection.
    10. Iterator iterator() returns an iterator.
    11. Object[] toArray() converts collection into array.
    12. boolean isEmpty() checks if collection is empty.
    13. boolean equals(Object element) matches two collection.
    14. int hashCode() returns the hashcode number for collection.

How ArrayList Works Internally in Java

ArrayList is a resizable array implementation of the List interface i.e. ArrayList grows dynamically as the elements are added to it.

If the size of the current elements (including the new element to be added to the ArrayList) is greater than the maximum size of the array then increase the size of array. But the size of the array can not be increased dynamically. So, what happens internally is, a new Array is created and the old array is copied into the new array.

Java LinkedList class

Java LinkedList class uses doubly linked list to store the elements. It provides a linked-list data structure. It inherits the AbstractList class and implements List and Deque interfaces. The important points about Java LinkedList are:

  • Java LinkedList class can contain duplicate elements.
  • Java LinkedList class maintains insertion order.
  • Java LinkedList class is non synchronized.
  • In Java LinkedList class, manipulation is fast because no shifting needs to be occurred.
  • Java LinkedList class can be used as list, stack or queue.

Doubly Linked List

In case of doubly linked list, we can add or remove elements from both side.

The Map Interface

Map is an object that maps keys to values. A map cannot contain duplicate keys: Each key can map to at most one value. It models the mathematical function abstraction. The Map interface includes methods for basic operations (such as put, get, remove, containsKey, containsValue, size, and empty), bulk operations (such as putAll and clear), and collection views (such as keySet, entrySet, and values).The Java platform contains three general-purpose Map implementations: HashMapTreeMap, and LinkedHashMap. Their behavior and performance are precisely analogous to HashSet, TreeSet, and LinkedHashSet, as described in The Set Interface section.

Java TreeMap class

Java TreeMap class implements the Map interface by using a tree. It provides an efficient means of storing key/value pairs in sorted order.

The important points about Java TreeMap class are:

  • A TreeMap contains values based on the key. It implements the NavigableMap interface and extends AbstractMap class.
  • It contains only unique elements.
  • It cannot have null key but can have multiple null values.
  • It is same as HashMap instead maintains ascending order.

264 thoughts on “The Collections framework in Java”

  1. Pingback: MBA tuition fees
  2. Pingback: Marketing program
  3. Pingback: Oral Surgery
  4. Pingback: Prosthodontics
  5. Pingback: Dr. Khaled Azazy
  6. Pingback: MSc in pharmacy
  7. Pingback: Biochemistry
  8. Pingback: controsoffitto led
  9. Pingback: led lineari
  10. Pingback: tomate musculation
  11. Pingback: metanail
  12. Pingback: Fiverr Earn
  13. Pingback: Fiverr Earn
  14. Pingback: Fiverr Earn
  15. Pingback: Fiverr Earn
  16. Pingback: Fiverr Earn
  17. Pingback: Fiverr Earn
  18. Pingback: Fiverr Earn
  19. Pingback: Fiverr Earn
  20. Pingback: Fiverr Earn
  21. Pingback: fiverrearn.com
  22. Pingback: fiverrearn.com
  23. Pingback: fiverrearn.com
  24. Pingback: fiverrearn.com
  25. Pingback: fiverrearn.com
  26. Pingback: fiverrearn.com
  27. Pingback: fiverrearn.com
  28. Pingback: fiverrearn.com
  29. Pingback: red boost
  30. Pingback: dallas frenchie
  31. Pingback: clima hoy
  32. Pingback: fiverrearn.com
  33. Pingback: fiverrearn.com
  34. Pingback: frenchie san diego
  35. Pingback: fluffy frenchies
  36. Pingback: micro bully
  37. Pingback: bernedoodle
  38. Pingback: bernedoodles
  39. Pingback: blogging
  40. Pingback: Safe Piano Removal
  41. Pingback: frenchie jewelry
  42. Pingback: swimsuit
  43. Pingback: future university
  44. Pingback: future university
  45. Pingback: future university
  46. Pingback: future university
  47. Pingback: Fiverr
  48. Pingback: Fiverr.Com
  49. Pingback: FiverrEarn
  50. Pingback: future university
  51. Pingback: lean six sigma
  52. Pingback: Piano refurbishing
  53. Pingback: FUE
  54. Pingback: FUE
  55. Pingback: FUE
  56. Pingback: FUE
  57. Pingback: Reliable movers
  58. Pingback: Moving trucks
  59. Pingback: Classic Books 500
  60. Pingback: FiverrEarn
  61. Pingback: FiverrEarn
  62. Pingback: FiverrEarn
  63. Pingback: Fiverr.Com
  64. Pingback: Fiverr
  65. Pingback: FiverrEarn
  66. Pingback: FiverrEarn
  67. Pingback: Streamer
  68. Pingback: Media
  69. Pingback: FiverrEarn
  70. Pingback: FiverrEarn
  71. Pingback: pupuk organik cair
  72. Pingback: pupuk terbaik
  73. Pingback: partners
  74. Pingback: FiverrEarn
  75. Pingback: live sex cams
  76. Pingback: live sex cams
  77. Pingback: live sex cams
  78. Pingback: live sex cams
  79. Pingback: FiverrEarn
  80. Pingback: FiverrEarn
  81. Pingback: FiverrEarn
  82. Pingback: FiverrEarn
  83. Pingback: FiverrEarn
  84. Pingback: FiverrEarn
  85. Pingback: FiverrEarn
  86. Pingback: FiverrEarn
  87. Pingback: FiverrEarn
  88. Pingback: FiverrEarn
  89. Pingback: FiverrEarn
  90. Pingback: FiverrEarn
  91. Pingback: FiverrEarn
  92. Pingback: FiverrEarn
  93. Pingback: FiverrEarn
  94. Pingback: FiverrEarn
  95. Pingback: FiverrEarn
  96. Pingback: FiverrEarn
  97. Pingback: FiverrEarn
  98. Pingback: FiverrEarn
  99. Pingback: FiverrEarn
  100. Pingback: FiverrEarn
  101. Pingback: FiverrEarn
  102. Pingback: Dairy
  103. Pingback: sns
  104. Pingback: Slot Online
  105. Pingback: FiverrEarn
  106. Pingback: FiverrEarn
  107. Pingback: FiverrEarn
  108. Pingback: FiverrEarn
  109. Pingback: leanbiome scam
  110. Pingback: fullersears.com
  111. Pingback: dog probiotics
  112. Pingback: french bulldog buy
  113. Pingback: live sex cams
  114. Pingback: OnOverseas.Com
  115. Pingback: live sex cams
  116. Pingback: freeze dried candy
  117. Pingback: frt trigger
  118. Pingback: efos y edos
  119. Pingback: Asesoria Fiscal
  120. Pingback: Alienlabs Xeno
  121. Pingback: 늑대닷컴
  122. Pingback: Bonus slot online
  123. Pingback: One Peace AMV
  124. Pingback: nangs near me
  125. Pingback: superslot
  126. Pingback: allgame
  127. Pingback: 918kiss
  128. Pingback: หวย24
  129. Pingback: Body Care
  130. Pingback: pg slot
  131. Pingback: Raahe Guide
  132. Pingback: Raahe Guide
  133. Pingback: slot online
  134. Pingback: upstate hotels
  135. Pingback: megagame
  136. Pingback: electronic visa
  137. Pingback: weight drops
  138. Pingback: 25-06 ammo
  139. Pingback: 35 whelen ammo
  140. Pingback: ozempic
  141. Pingback: sicarios madrid
  142. Pingback: itsMasum.Com
  143. Pingback: itsMasum.Com
  144. Pingback: itsMasum.Com
  145. Pingback: itsMasum.Com
  146. Pingback: nang tanks
  147. Pingback: website

Comments are closed.

JavaScript and its most used frameworks and libraries
Prev post JavaScript and its most used frameworks and libraries
264 Comments

Frameworks try to solve most of the big and known problems that are usually encountered…

Servers
Next post Servers
264 Comments

Servers have been around as long as networks. A server is a computer program which…