TreeMap int size() Method Example Program


Returns the number of key-value mappings in this map.

Program

package com.candidjava;

import java.util.TreeMap;

/**
 * @author: Hari Haran
 * @discription: The size() method is used to return the number of key-value
 *               mappings in this map.
 */

public class TreeMapSize {
	public static void main(String[] args) {
		TreeMap<Integer, String> tm = new TreeMap<Integer, String>();

		tm.put(1, "Anand");
		tm.put(2, "Hari Haran");
		tm.put(8, "Kamal");
		tm.put(4, "Karthikeyan");
		tm.put(5, "Mohan");
		tm.put(6, "Vinoth");
		tm.put(7, "Hari Haran");

		System.out.println("Size of the map: " + tm.size());
	}
}

Output

Size of the map: 7

Explanation

public int size()
Returns the number of key-value mappings in this map.
Specified by:
size in interface Map<K,V>
Overrides:
size in class AbstractMap<K,V>
Returns:
the number of key-value mappings in this map


Related Post

Comments


©candidjava.com