public class Pair<K, V> {
private K key;
private V value;
public Pair(K key, V value) {
this.key = key;
this.value = value;
}
public K getKey() {
return this.key;
}
public V getValue() {
return this.value;
}
public static void main(String[] args) {
Pair<Integer, String> p1 = new Pair<>(123, "Generics");
Integer key = p1.getKey();
String value = p1.getValue();
System.out.println("Key: " + key);
System.out.println("Value: " + value);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter