Home » Java programming language

Java Collections checkedSortedMap() Method with Example

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

Collections Class checkedSortedMap() method

  • checkedSortedMap() Method is available in java.lang package.
  • checkedSortedMap() Method is used to return the typesafe view of the given SortedMap at runtime.
  • checkedSortedMap() Method is a static method, so it is accessible with the class name and if we try to access the method with the class object then we will not get an error.
  • checkedSortedMap() Method does not throw an exception at the time of returning validated SortedMap.


    public static SortedMap checkedSortedMap(
        SortedMap sm, 
        Class key_ty, 
        Class val_ty


  • SortedMap sm – represents the Sorted map for which to get typesafe view of the given sorted map at runtime.
  • Class key_ty – represents the key type that the given map is allowed to store.
  • Class val_ty – represents the value type that the given map is allowed to store.

Return value:

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


// Java Program is to demonstrate the example
// of SortedMap checkedSortedMap(SortedMap sm, Class key_ty, Class val_ty) 
// of Collections class

import java.util.*;

public class CheckedSortedMap {
    public static void main(String args[]) {
        // Create a sortedmap object    
        SortedMap < Integer, String > sm = new TreeMap < Integer, String > ();

        // By using put() method is to add the
        // given elements in tree map
        sm.put(20, "C");
        sm.put(10, "C++");
        sm.put(30, "JAVA");
        sm.put(40, "DOTNET");
        sm.put(50, "PHP");

        // Display SortedMap
        System.out.println("sortedmap: " + sm);

        // By using checkedSortefMap() method is to 
        // represent the type safe view of the given
        // Collection sorted map

        SortedMap < Integer, String > s_m = Collections.checkedSortedMap(sm, Integer.class, String.class);

        System.out.println("Collections.checkedSortedMap(sm, Integer.class,String.class) :");

        // Display collection
        System.out.println("sortedmap: " + s_m);


sortedmap: {10=C++, 20=C, 30=JAVA, 40=DOTNET, 50=PHP}

Collections.checkedSortedMap(sm, Integer.class,String.class) :
sortedmap: {10=C++, 20=C, 30=JAVA, 40=DOTNET, 50=PHP}


Comments and Discussions



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

© some rights reserved.