Showing posts with label coltoc. Show all posts
Showing posts with label coltoc. Show all posts

Saturday, 28 May 2011

Lists In Java

A List(in the API reference documentation)is an ordered Collection(in the API reference documentation)(sometimes called a sequence). Lists may contain duplicate elements. In addition to the operations inherited from Collection, the List interface includes operations for:

  • Positional Access: manipulate elements based on their numerical position in the list.
  • Search: search for a specified object in the list and return its numerical position.
  • List Iteration: extend Iterator semantics to take advantage of the list's sequential nature.
  • Range-view: perform arbitrary range operations on the list.

List Interface

List Implementations

 

Comparing List to Vector

ListIterator Interface

Operations on Lists

There are various type of operations that can be performed on lists:


Generic Lists in Java
Performance of List implementations in java

Friday, 27 May 2011

Map implementations in java

A number of classes implement the Map interface, including HashMap, TreeMap, LinkedHashMap, WeakHashMap, ConcurrentHashMap, and Properties. The most generally useful class is HashMap.
  • java.util.HashMap is implemented with a hash table. Access time is O(1). Entries are unsorted.
    – similar to HashTable but allows null keys and values
    – not thread safe
  • java.util.LinkedHashMap is implemented with a hash table. Access time is O(1). Entries are sorted in either entry order or order of last access, which is useful for implementing a LRU (least recently used) caching policy.
  • java.util.TreeMap is implemented as a balanced binary tree. Access time is O(log N). Entries are sorted. 
  • java.util.HashTable(old classes)
    – updated class from earlier Java versions
    – does not allow null keys or values
    – thread safe
  • java.util.WeakHashMap -
    – like HashMap
    – entry is automatically removed from HashMap if no more "ordinary" references to key
  • java.util.IdentityHashMap
  • java.util.EnumMap
  • java.util.Properties

Sunday, 17 April 2011

Set tutorial in java

A Set(in the API reference documentation) is a Collection(in the API reference documentation) that cannot contain duplicate elements. Set models the mathematical set abstraction. The Set interface contains no methods other than those inherited from Collection. It adds the restriction that duplicate elements are prohibited. Set also adds a stronger contract on the behavior of the equals and hashCode operations, allowing Set objects with different implementation types to be compared meaningfully. Two Set objects are equal if they contain the same elements.
 

Set Interfaces

 

Set Implementations

 

Operations on Sets

 

SortedSet

 

How is set implemented internally?

Set and serializations

Sets and synchronization

Iterators returned by set implementation and concurrent modification

When to use which set implementation?

Performance of set interface implementations

 

Saturday, 12 March 2011

The SortedSet interface

A SortedSet(in the API reference documentation)is a Set(in the API reference documentation)that maintains its elements in ascending order, sorted according to the elements' natural order, or according to a Comparator provided at SortedSet creation time. (Natural order and Comparators are discussed in the previous section, on Object Ordering.) In addition to the normal Set operations, the Set interface provides operations for:
  • Range-view: Performs arbitrary range operations on the sorted set.
  • Endpoints: Returns the first or last element in the sorted set.
  • Comparator access: Returns the Comparator used to sort the set (if any).

The SortedSet interface is shown below:

public interface SortedSet extends Set {
// Range-view
SortedSet subSet(Object fromElement, Object toElement);
SortedSet headSet(Object toElement);
SortedSet tailSet(Object fromElement);
// Endpoints
Object first();
Object last();
// Comparator access
Comparator comparator();
}





SortedSet Operations 


Standard Constructors 


Range-view Operations on SortedSet


Example – Creating a SortedSet