Collections Tutorial Step 2

Some of the very useful interfaces of Collection Framework

Iterators - Similar to the familiar Enumeration interface, but more powerful, and with improved method names.

  • Iterator - In addition to the functionality of the Enumeration interface, allows the user to remove elements from the backing collection with well defined, useful semantics.
  • ListIterator - Iterator for use with lists. In addition to the functionality of the Iterator interface, supports bi-directional iteration, element replacement, element insertion and index retrieval.

Ordering

  • Comparable - Imparts a natural ordering to classes that implement it. The natural ordering may be used to sort a list or maintain order in a sorted set or map. Many classes have been retrofitted to implement this interface.
  • Comparator - Represents an order relation, which may be used to sort a list or maintain order in a sorted set or map. Can override a type's natural ordering, or order objects of a type that does not implement the Comparable interface.

Array Utilities

  • Arrays - Contains static methods to sort, search, compare, hash, convert to String, and fill arrays of primitives and Objects.

Some of the Basic Operations available in Collection Framework

  • sort - Sorts a list using a merge sort algorithm, which provides average-case performance comparable to a high-quality quicksort, guaranteed O(n*log n) performance (unlike quicksort), and stability (unlike quicksort). (A stable sort is one that does not reorder equal elements.)
  • binarySearch - Searches for an element in an ordered list using the binary search algorithm.
  • reverse - Reverses the order of the elements in the a list.
  • shuffle - Randomly permutes the elements in a list.
  • fill - Overwrites every element in a list with the specified value.
  • copy - Copies the source list into the destination list.
  • min - Returns the minimum element in a collection.
  • max - Returns the maximum element in a collection.
  • rotate - Rotates all of the elements in the list by the specified distance.
  • replaceAll - Replaces all occurrences of one specified value with another.
  • indexOfSubList - Returns the index of the first sublist of source that is equal to target.
  • lastIndexOfSubList - Returns the index of the last sublist of source that is equal to target.
  • swap- Swaps the elements at the specified positions in the specified list.
  • frequency - Counts the number of times the specified element occurs in the specified collection.
  • disjoint - Determines whether two collections are disjoint, in other words, whether they contain no elements in common.
  • addAll - Adds all of the elements in the specified array to the specified collection.

AddThis Feed Button
Please provide your feedback by sending an email to 1234java.blogspot@gmail.com. This would help me making the site more helpful. Thanks in advance.

DISCLAIMER:

The content provided in this article/site is not warranted or guaranteed by 1234java.blogspot.com. The content provided is intended for educational purposes in order to introduce to the reader key ideas, concepts. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials.