You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
559 B

public class PairTest {
public static void main(String[] args) {
// 1. 创建原始 Pair
Pair<String, Integer> p1 = new Pair<>("身高", 180);
System.out.println("交换前:" + p1);
// 2. 调用静态swap方法交换键值
Pair<Integer, String> p2 = Pair.swap(p1);
System.out.println("交换后:" + p2);
// 再测试一组
Pair<Integer, Double> p3 = new Pair<>(10, 99.5);
Pair<Double, Integer> p4 = Pair.swap(p3);
System.out.println("另一组交换:" + p4);
}
}