Skip to content
Related Articles

Related Articles

Improve Article
AbstractMap.SimpleEntry getValue() Method in Java with Examples
  • Last Updated : 27 Jun, 2019

AbstractMap.SimpleEntry<K, V> is used to maintain a key and a value entry. The value can be changed using the setValue method. This class facilitates the process of building custom map implementations.

getValue() method of AbstractMap.SimpleEntry<K, V> returns the value corresponding to a entry made in this class.

Syntax:

public K getValue()

Parameters: This method accepts nothing.

Return value: This method returns the value corresponding to this entry.



Below programs illustrate getValue() method:
Program 1:




// Java program to demonstrate
// AbstractMap.SimpleEntry.getValue() method
  
import java.util.*;
import java.util.AbstractMap.SimpleEntry;
  
public class GFG {
  
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static void main(String[] args)
    {
  
        // create a ArrayList of Map
        ArrayList<AbstractMap
.SimpleEntry<Integer, Integer> > 
arrayList
 = new ArrayList<AbstractMap
.SimpleEntry<Integer, Integer> >();
  
        // add values
        arrayList.add(new AbstractMap.SimpleEntry(0, 123));
        arrayList.add(new AbstractMap.SimpleEntry(1, 130));
        arrayList.add(new AbstractMap.SimpleEntry(2, 994));
  
        // print keys
        for (int i = 0; i < arrayList.size(); i++) {
  
            // get map from list
            AbstractMap.SimpleEntry<Integer, Integer>
 map = arrayList.get(i);
  
            // get value from map using getValue()
            int value = map.getValue();
  
            System.out.println("Value " + value);
        }
    }
}
Output:
Value 123
Value 130
Value 994

Program 2:




// Java program to demonstrate
// AbstractMap.SimpleEntry.getValue() method
  
import java.util.*;
  
public class GFG {
  
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static void main(String[] args)
    {
  
        // create a ArrayList of Map
        ArrayList<AbstractMap
.SimpleEntry<String, String> > 
arrayList
 = new ArrayList<AbstractMap
.SimpleEntry<String, String> >();
  
        // add values
        arrayList.add(new AbstractMap
.SimpleEntry(" 001AB ", " Emp 1"));
        arrayList.add(new AbstractMap
.SimpleEntry(" 011AC ", " Emp 2"));
        arrayList.add(new AbstractMap
.SimpleEntry(" 111AD ", " Emp 3"));
        arrayList.add(new AbstractMap
.SimpleEntry(" 101BE ", " Emp 4"));
        arrayList.add(new AbstractMap
.SimpleEntry(" 110CE ", " Emp 5"));
  
        // print keys
        for (int i = 0; i < arrayList.size(); i++) {
  
            // get map from list
            AbstractMap.SimpleEntry<String, String> 
map = arrayList.get(i);
  
            // get value from map using getValue()
            String value = map.getValue();
  
            System.out.println("Value " + value);
        }
    }
}
Output:
Value  Emp 1
Value  Emp 2
Value  Emp 3
Value  Emp 4
Value  Emp 5

References: https://docs.oracle.com/javase/10/docs/api/java/util/AbstractMap.SimpleEntry.html#getValue()

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :