10:26 pm - Monday March 27, 2017

Archive: Java Examples Subscribe to Java Examples

clear all elements from treemap void Clear()

BACK                   This tutorial explains how to clear all elements from treemap using Clear() method.we can’t clear the particular data ,it will clear all the data. Example import java.util.TreeMap; public...

Retrieve value of given Key in Treemap V get(Object key)

BACK                      This tutorial explains how to Retrieve value of given Key in treemap using get(Object key) method.  Returns the value to which the specified key is mapped, or null if this map contains no mapping...

Add key value pair to Treemap V put(K key,V value)

BACK   This tutorial explains how to Add key value pair to Treemap using V put() method.It Associates the specified value with the specified key in this map.   Example import java.util.java.util.TreeMap; public class TreeMapPut { public...

Treemap example programs and Tutorial in java

Treemap example programs and Tutorial in java

BACK   1. Add key value pair to Treemap V put(K key,V value) 2. Retrieve value of given Key in Treemap V get(Object key) 3. Remove a data from treemap by its key V remove(Object key) 4. Clear all elements from treemap  void Clear() 5....

Dynamically typesafe view in collection using public static Collection checkedCollection(Collection c, Classtype)

BACK                           The method is used to get a dynamically typesafe view of the specified collection. Example Program import java.util.Collections; import java.util.Collection; import java.util.ArrayList; public...

Copy of elements from one to another in collection using public static void copy(Listdest, Listsrc)

BACK                    The method is used to copy all of the elements from one list into another. Example Program import java.util.Collections; import java.util.ArrayList; public class collectionCopy { public...

Typesafe view by specified Map in collection public static Map checkedMap(Map m, Class keyType, Class valueType)

BACK                         The method is also used to typesafe view by used specified map. Example Program import java.util.Collections; import java.util.HashMap; import java.util.Map; public class collectionCheckedMap { public...

Reverse the order of elements in collection using public static void reverse(list list)

BACK                           The method is used to reverse the order of the elements in the specified list. Example Program import java.util.Collections; import java.util.HashMap; import java.util.Map; public...

Replace all elements of a list using public static void fill(List list,T obj)

BACK                         This method is also used to replace all of the elements of the specified list with the specified element. Example Program import java.util.Collections; import java.util.ArrayList; public...

Swap the element in collection using public static void swap(List list,int i, int j)

BACK                              The method is used to swap the elements at the specified positions in the specified list. Example Program import java.util.Collections; import java.util.ArrayList; public...

Replace all value with another list in collection using public static boolean replaceAll(Listlist,T oldVal,T newVal)

BACK                        The method is used to replace all occurrences of one specified value in a list with another. Example Program import java.util.Collections; import java.util.ArrayList; public class collectionReplaceAll { public...

Search a particular list in collection using binarySearch(List,T,Comparator)

BACK                           The method is used to search the specified list for the specified object using the binary search algorithm. The list must be sorted into ascending order according to the specified comparator. Example...

View of Deque in Last-in-first-out order using asLifoQueue()

BACK                        The asLifoQueue(Deque<T>) method is used to get a view of a Deque as a Last-in-first-out  Queue.The method of Queue should be in lifo order. Example Program import java.util.Collections; import...

Search whether object is present in stack using int search(Object o)

BACK The method is used to search where an object in stack. If the object occurs  in that stack , at that time search operation will occur the method returns the distance from the top of the stack of the occurrence nearest the top of the...

Push an item on top of the stack using E push(E item)

BACK                   The push( ) method Pushes an item onto the top of this stack. Example Program import java.util.Stack; public class Stackpush { public static void main(String args[]) { Stack n =...

Remove object at the top of stack using E pop()

BACK                   The pop() method is used to remove the object at the top of this stack and returns that object as the value of this function. Example Program import java.util.Stack; public class Stackpop { public...

Look object at top of the stack using E peek( )

BACK                             The  peek( )method is used to look at the object at the top of this stack without removing it from the stack. Example Program import java.util.Stack; public class Stackpeek...

Check whether stack is empty using boolean empty( )

BACK The empty() method is used to test if this stack is or not.Tests if this stack is empty. Returns true if the stack is empty, and returns false if the stack contains elements. Example Program import java.util.Stack; public...

Remove all elements from a collection boolean removeAll(Collection c)

BACK                      The method public boolean removeAll(Collection<?c)  removes all the elements from the given collection. After performing removeAll function the set remains 0 elements. Example Program import...