1.如果返回2个或3个值,又懒得去定义bean,map,json之类的,那还有什么好办法呢?
答案是肯定有的。
2.代码
先引入maven依赖
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.11</version>
</dependency>
返回2个结果的
MutablePair<String, String> mutablePair = MutablePair.of("1", "第二个值"); System.out.println(mutablePair.getLeft() + "," + mutablePair.getRight());
返回3个结果
MutableTriple<Integer, String, Date> mutableTriple = MutableTriple.of(2, "中间值", new Date()); System.out.println(mutableTriple.getLeft() + "," + mutableTriple.getMiddle() + "," + mutableTriple.getRight());