View RSS Feed

Collections Framework

Java Collections Framework

  1. Enumerations and Iterators

    by , 11-08-2011 at 06:31 PM (My Java Tips)
    An Enumeration is used for iterating over a given collection, Usually of unknown size. Iterator also has the same purpose but Enumeration does not allow modification of the collection, Which can be achieved using Iterator.

    Iterator’s "remove" method removes from the underlying collection the last element returned by the iterator. This method can be called only once per call to the Iterator's "next" method.

    Following code sample will help you understand ...
  2. Using Vectors

    by , 11-08-2011 at 06:26 PM (My Java Tips)
    When using arrays, you have to give their size at declaration. So arrays do not expand dynamically. Vectors expand automatically when data is added to them. Vector class is included in java.util package. Vectors are used to store Objects.

    Vector is thread safe. It means Vectors are synchronized, means you can use Vectors even if your object might be shared by two or more threads at a same time. This makes Vector slower than ArrayList which is not thread safe.

    Following ...
  3. Rotating Elements In a List using Collections.rotate Method

    by , 11-08-2011 at 06:22 PM (My Java Tips)
    Collections have very useful methods. Let us see how to rotate objects in a given list. The method "rotate" has two inputs, a list and a distance parameter which defines rotation distance. The distance can be positive, negative or zero. Objects in the list will be rotated by the specified parameter. Let us take an example to rotate objects of Car class.

    For example, suppose list comprises [t, a, n, k, s]. After invoking



    Collections.rotate(list, 1) ...
  4. How to Sort Objects Using Collections.sort method

    by , 11-08-2011 at 06:19 PM (My Java Tips)
    A programmer usually needs to sort a given set of inputs. Java has inbuilt set of API's for sorting. There is a Comparable interface in java that needs to be implemented by class whose object needs to be compared. Java classes like "Integer", "Date" implements this interface, so object of these classes can be sorted easily by Collection's sort method. We can make a class that implements Comparable interface so that it's objects can be sorted by "Collections.sort" method. ...
  5. Introduction To Collections In Java

    by , 11-08-2011 at 05:56 PM (My Java Tips)
    Framework is a set of classes that acts as a base for building some advanced functionality. It contains super classes having useful functionality and mechanisms which can either be used directly or can be extended in form of subclasses so as to extend the functionality without having to reinvent the basic mechanisms. For example, AWT is a framework for user interfaces.



    The Java collections library is a framework for collection classes. It includes a number of interfaces and ...
  6. More on Collection FrameWork

    by , 11-08-2011 at 05:54 PM (My Java Tips)
    Here we assume that programmer is well aware about the basic concepts of Collections Framework. For more information about basics on Collection Framework click here.
    Now have a look on the classes that implement the " Collection " and " Map " interface.

    As the collection interfaces have a few methods that can be easily implemented from fundamental methods where as abstract classes in the collection framework supply some of these routine implementations. ...