您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

存储一个字符串和两个双打java

存储一个字符串和两个双打java

一个不错的通用解决方案:

public class Triple<L, K, V> {

    private final L first;
    private final K second;
    private final V third;

    public Triple(L first, K second, V third) {
        this.first = first;
        this.second = second;
        this.third = third;
    }

    public L getFirst() {
        return this.first;
    }

    public K getSecond() {
        return this.second;
    }

    public V getThird() {
        return this.third;
    }

}

可以这样实现:

Triple<String, Integer, Integer> myTriple = new Triple<>("Hello world", 42, 666);

但是这里的真正概念是将数据点表示为代码中的 。如果您有一组数据(“我有一个字符串和两个表示 某些 含义的整数”),那么您希望将其封装在一个类下。

java 2022/1/1 18:37:58 有353人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶