diff --git a/W8/Pair.java b/W8/Pair.java new file mode 100644 index 0000000..976abea --- /dev/null +++ b/W8/Pair.java @@ -0,0 +1,26 @@ +public class Pair { + private K key; + private V value; + + // 构造方法 + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + // Getter 和 Setter + public K getKey() { return key; } + public V getValue() { return value; } + public void setKey(K key) { this.key = key; } + public void setValue(V value) { this.value = value; } + + @Override + public String toString() { + return "(" + key + ", " + value + ")"; + } + + // 静态交换方法 + public static Pair swap(Pair p) { + return new Pair<>(p.getValue(), p.getKey()); + } +}