Home » Java programming language

Java Collections synchronizedSortedMap() Method with Example

Collections Class synchronizedSortedMap() method: Here, we are going to learn about the synchronizedSortedMap() method of Collections Class with its syntax and example.
Submitted by Preeti Jain, on February 07, 2020

Collections Class synchronizedSortedMap() method

  • synchronizedSortedMap() method is available in java.util package.
  • synchronizedSortedMap() method is used to return the synchronized view of the given sorted map (sm).
  • synchronizedSortedMap() method is a static method, it is accessible with the class name and if we try to access the method with the class object then also we will not get any error.
  • synchronizedSortedMap() method does not throw an exception at the time of returning synchronized sorted map.


    public static SortedMap synchronizedSortedMap(SortedMap sm);


  • SortedMap sm – represents the sorted map to be viewed in synchronized sorted map.

Return value:

The return type of this method is SortedMap, it returns synchronized view of the given sorted map.


// Java program to demonstrate the example 
// of SortedMap synchronizedSortedMap() method 
// of Collections

import java.util.*;

public class SynchronizedSortedMapOfCollections {
    public static void main(String args[]) {
        // Instantiates a sorted map object
        SortedMap < Integer, String > tm = new TreeMap < Integer, String > ();

        // By using put() method is to add
        // objects in a treemap 
        tm.put(10, "C");
        tm.put(20, "C++");
        tm.put(30, "JAVA");
        tm.put(40, "PHP");
        tm.put(50, "SFDC");

        // Display TreeMap
        System.out.println("TreeMap: " + tm);

        // By using synchronizedSortedMap() method is to
        // represent the treemap in synchronized view
        tm = Collections.synchronizedSortedMap(tm);

        // Display Synchronized SortedMap
        System.out.println("Collections.synchronizedSortedMap(tm): " + tm);


TreeMap: {10=C, 20=C++, 30=JAVA, 40=PHP, 50=SFDC}
Collections.synchronizedSortedMap(tm): {10=C, 20=C++, 30=JAVA, 40=PHP, 50=SFDC}

Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.