Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
SortedMap keySet() method in Java with Examples
Next article icon

SortedMap values() method in Java with Examples

Last Updated : 26 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The values() method of SortedMap interface in Java is used to create a collection out of the values of the map. It basically returns a Collection view of the values in the Map. Syntax:
SortedMap.values()
Parameters: The method does not accept any parameters. Return Value: The method is used to return a collection view containing all the values of the map. Below programs are used to illustrate the working of above method: Program 1: Mapping String Values to Integer Keys. Java
// Java code to illustrate the values() method  import java.util.*;  public class SortedMapDemo {     public static void main(String[] args)     {          // Creating an empty TreeMap         SortedMap<Integer, String>             sotree_map = new TreeMap<Integer, String>();          // Mapping string values to int keys         sotree_map.put(10, "Geeks");         sotree_map.put(15, "4");         sotree_map.put(20, "Geeks");         sotree_map.put(25, "Welcomes");         sotree_map.put(30, "You");          // Displaying the TreeMap         System.out.println("Initial Mappings are: "                            + sotree_map);          // Using values() to get the set view of values         System.out.println("The collection is: "                            + sotree_map.values());     } } 
Output:
  Initial Mappings are: {10=Geeks, 15=4, 20=Geeks, 25=Welcomes, 30=You}  The collection is: [Geeks, 4, Geeks, Welcomes, You]  
Program 2: Mapping Integer Values to String Keys. Java
// Java code to illustrate the values() method  import java.util.*;  public class SortedMapDemo {     public static void main(String[] args)     {          // Creating an empty TreeMap         SortedMap<String, Integer>             sotree_map = new TreeMap<String, Integer>();          // Mapping int values to string keys         sotree_map.put("Geeks", 10);         sotree_map.put("4", 15);         sotree_map.put("Geeks", 20);         sotree_map.put("Welcomes", 25);         sotree_map.put("You", 30);          // Displaying the TreeMap         System.out.println("Initial Mappings are: "                            + sotree_map);          // Using values() to get the set view of values         System.out.println("The collection is: "                            + sotree_map.values());     } } 
Output:
  Initial Mappings are: {4=15, Geeks=20, Welcomes=25, You=30}  The collection is: [15, 20, 25, 30]  
Note: The same operation can be performed with any type of Mappings with variation and combination of different data types.

Next Article
SortedMap keySet() method in Java with Examples

C

chinmoy lenka
Improve
Article Tags :
  • Misc
  • Java
  • Java-Collections
  • Java - util package
  • Java-Functions
  • Java-SortedMap
Practice Tags :
  • Java
  • Java-Collections
  • Misc

Similar Reads

    SortedMap Interface in Java
    SortedMap is an interface in the collection framework that is a part of java.util package and extends the Map interface. It represents a map that maintains its keys in a sorted order. The keys in a SortedMap are sorted according to their natural ordering or by a Comparator provided at the time of ma
    10 min read
    SortedMap tailMap() method in Java
    The tailMap() method of SortedMap interface in Java is used to return a view of the portion of this map whose keys are greater than or equal to fromKey. The map returned by this method is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The map returned b
    3 min read
    SortedMap firstKey() method in Java
    The firstKey() method of SortedMap interface in Java is used to return the first or the lowest key currently in this map. Syntax: K firstKey() Where, K is the type of key maintained by this Set. Parameters: This function does not accepts any parameter. Return Value: It returns the first print the lo
    2 min read
    SortedMap lastKey() method in Java
    The lastKey() method of SortedMap interface in Java is used to return the last or the greatest key currently in this map. Syntax: K lastKey() Where, K is the type of key maintained by this Set. Parameters: This function does not accepts any parameter. Return Value: It returns the last or the greates
    2 min read
    SortedMap comparator() method in Java with Examples
    The comparator() method of java.util.SortedMap interface is used to return the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.Syntax: public Comparator comparator() Return Value: This method returns the comparator used to order the keys in th
    2 min read
    SortedMap values() method in Java with Examples
    The values() method of SortedMap interface in Java is used to create a collection out of the values of the map. It basically returns a Collection view of the values in the Map. Syntax: SortedMap.values() Parameters: The method does not accept any parameters. Return Value: The method is used to retur
    2 min read
    SortedMap keySet() method in Java with Examples
    The keySet() method of SortedMap Interface in Java is used to create a set out of the key elements contained in the treemap. It basically returns a set view of the keys or we can create a new set and store the key elements in them in an ascending order. Since the set is backed by the map, any change
    2 min read
    SortedMap entrySet() method in Java with Examples
    The entrySet() method of SortedMap interface in Java is used to create a set out of the same elements contained in the map. It basically returns a set view of the map or creates a new set and store the map elements into them. Syntax: SortedMap.entrySet() Parameters: The method does not take any para
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences