AbstractMap.SimpleEntry 用于维护键和值条目。可以使用setValue方法更改该值。此类有助于构建自定义Map实现。
AbstractMap.SimpleEntry 的getValue()方法返回对应于此类中的条目的值。
用法:
public K getValue()
参数:此方法不接受任何内容。
返回值:此方法返回与此条目对应的值。
以下示例程序旨在说明getValue()方法:
程序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
.SimpleEntry >
arrayList
= new ArrayList
.SimpleEntry >();
// 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
map = arrayList.get(i);
// get value from map using getValue()
int value = map.getValue();
System.out.println("Value " + value);
}
}
}
输出:
Value 123
Value 130
Value 994
程序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
.SimpleEntry >
arrayList
= new ArrayList
.SimpleEntry >();
// 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
map = arrayList.get(i);
// get value from map using getValue()
String value = map.getValue();
System.out.println("Value " + value);
}
}
}
输出:
Value Emp 1
Value Emp 2
Value Emp 3
Value Emp 4
Value Emp 5