TreeMap containsValue() method in java

import java.util.TreeMap;
public class TreeMapContainsValueMethodExample
{
   public static void main(String[] args)
   {
      TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
      // Map string values to integer keys
      tm.put(16, "indigo");
      tm.put(12, "red");
      tm.put(14, "indigo");
      tm.put(18, "orange");
      tm.put(20, "violet");
      System.out.println("TreeMap before using containsValue() method: " + tm);
      // checking for Value 'indigo'
      System.out.println("Does value 'indigo' present? " + tm.containsValue("indigo"));
      // checking for Value 'blue'
      System.out.println("Does value 'blue' present? " + tm.containsValue("blue"));
   }
}

3.67
3

                                    map Integer values to String keys
import java.util.TreeMap;
public class TreeMapContainsValueMethodExample
{
   public static void main(String[] args)
   {
      TreeMap&lt;String, Integer&gt; tm = new TreeMap&lt;String, Integer&gt;();
      // Map integer values to string keys
      tm.put(&quot;indigo&quot;, 16);
      tm.put(&quot;red&quot;, 12);
      tm.put(&quot;indigo&quot;, 14);
      tm.put(&quot;orange&quot;, 18);
      tm.put(&quot;violet&quot;, 20);
      System.out.println(&quot;TreeMap before using containsValue() method: &quot; + tm);
      // Checking for the Value '12'
      System.out.println(&quot;Does value '12' present? &quot; + tm.containsValue(12));
      // Checking for the Value '14'
      System.out.println(&quot;Does value '14' present? &quot; + tm.containsValue(14));
      // Checking for the Value '20'
      System.out.println(&quot;Does value '20' present? &quot; + tm.containsValue(20));
   }
}

3.67 (3 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source