VisualBuilder
  Home > Java > Tutorials > ConcurrentSkipListMap Class - Java 1.6 Tutorial
Tell a friend
Link to us
Total Members
      Members: 84772
     
Sitemap Forum Chat
Home
Java 1.6 Tutorial Home
1 . Collections Enhancements
2 . Console Class
3 . ArrayDeque Class
4 . ConcurrentSkipListMap Class
5 . ConcurrentSkipListSet Class
6 . HashSet Collection Framework
7 . Java.util
8 . File and Directory Permissions in JDK1.6
9 . Core Java Internationalization
10 . Enhanced memory leak analysis and detection
11 . Changes in NetworkInterface Class
12 . API Changes
13 .  Compression Using Java 6
14 . ZipOutputStream Class To Compress Files in Zip Format
15 . ZipInputStream Class To Decompress Zip files
16 . Enhancements for Web Services
17 . Steps to use the Scripting API
18 . Java Scripting API Introduction
 
 
Java Home
Java Members (27650)
Java Member Articles ( 40 )
Java Discussion (275)
Java Q & A ( 174 )
- Java Ask Question
- Java Questions
- Java Unanswered Questions
Java Resources
Java Source Code (1096)
Java Articles (551)
Java Blogs (118)
Java Jobs (797)
Java Components (85)
Java Books (169)
Java Websites (127)
Java News (103)
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.Net Security,Internationalisation And Deployment
ASP.NET Tutorial
C# Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (451 )
Source Code (3275 )
Articles (359 )
Books (372 )
Components (1596 )
News (892 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise

Java java6 Tutorial
 ConcurrentSkipListMap Class
  << Prev: ArrayDeque Class Next: ConcurrentSkipListSet Class >>

ConcurrentSkipListMap is one of the class which implements NavigableMap.

This class implement all of the optional methods of the Map and Iterator interfaces. Like most other concurrent collections, this class does not permit the use of null keys or values because some null return values cannot be reliably distinguished from the absence of elements. NavigableMap class is similar to NavigableSet. In NavigableMap we use methods to return the key value pair like navMap.put(1, "sunday") whereas in NavigableSet we use methods to return values.



Let's have a look at the example.










import java.util.*;

import java.util.concurrent.*;


public class UseNavigableMap

{

 public static void main (String[] arg)

 {

   System.out.println("Example of Navigable Map ");

   NavigableMap navmap=new ConcurrentSkipListMap();

    navmap.put(1, "Sunday");  

    navmap.put(2, "Monday");

    navmap.put(3, "Tuesday");

    navmap.put(4, "Wednesday");

    navmap.put(5, "Thursday");

    navmap.put(6, "Friday");

    navmap.put(7, "Saturday");

 System.out.println("Data in the navigable map: " + navmap.descendingMap()+"\n");

//Retrieving first data

    System.out.println("First data: " + navmap.firstEntry()+"\n");

    //Retrieving last data

    System.out.print("Last data: " + navmap.lastEntry()+"\n");

    //Retrieving the nearest less than or equal to the given key

    System.out.println("Nearest less than or equal to the given key: " + navmap.floorEntry(5)+"\n");

    //Retrieving the greatest key strictly less than the given key

    System.out.println("Retrieving the greatest key strictly less than 

                         the given key: "
 + navmap.lowerEntry(3));

    //Retrieving a key-value associated with the least key strictly greater than the given key

    System.out.println("Retriving data from navigable map greater than the given key:    " + navmap.higherEntry(5)+"\n");

    //Removing first

    System.out.println("Removing First: " + navmap.pollFirstEntry());

    //Removing last

    System.out.println("Removing Last: " + navmap.pollLastEntry()+"\n");

    //Displaying all data

    System.out.println("Now data: " + navmap.descendingMap());

  }

}






NOTE:

The following program helps you in inserting, removing and retrieving the data from the NavigableMap. It uses the put() method to add the element, firstEntry() method to retrieve the data at first and lastEntry() methods to retrieve the  last position from the NavigableMap. The descendingMap() method represents all data to the NavigableMap in descending order. 


 


 











 


import java.util.*;
import java.util.concurrent.*;
class NavigableMapExample
{
public static void main(String[] args)
{

NavigableMap nm = new ConcurrentSkipListMap();
nm.put(1,"One");
nm.put(2,"Two");
nm.put(3,"Three");
nm.put(4,"Four");
nm.put(5,"Five");
/* Retrieves the key,value pair immediately lesser than the given key */
Map.Entry ae = nm.lowerEntry(5);
/* Map.Entry is a Static interface nested inside Map interface,just use to hold key and value */
System.out.println("Key" + ae.getKey());
System.out.println("Value"+ ae.getValue());
/* Retrieves key,value pairs equal to and greater then the given key */
SortedMap mm = nm.tailMap(3);
Set s = mm.keySet();
System.out.println("Tail elements are");
for(Integer i:s)
{
System.out.println("Key "+ i + "Value "+ mm.get(i));
}
}
}

Output:

Key 4 Value Four

Tail elements are
Key 3 Value Three
Key 4 Value Four
Key 5 Value Five

 


Notes :  
1. floorEntry method retrieves less than or equal to the givenkey (or) null.
2. lowerEntry method retrieves always less than the givenkey (or) null.
3. headMap method retrieves all elements less than the givenkey.
4. tailMap method retrieves all elements greater than or equal to the givenkey.




 


  << Prev: ArrayDeque Class Next: ConcurrentSkipListSet Class >>
Java Java6 Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
internet fax
Montignac Shop
 
 
ADVERTISEMENT
Partner List
Code Project
ASP Alliance
More
 
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising