Lou*_*man 10
有几个选择:
编写自定义IntPair类
class IntPair {
// Ideally, name the class after whatever you're actually using
// the int pairs *for.*
final int x;
final int y;
IntPair(int x, int y) {this.x=x;this.y=y;}
// depending on your use case, equals? hashCode? More methods?
}
Run Code Online (Sandbox Code Playgroud)
然后创建一个IntPair[]或一个List<IntPair>.
或者,创建一个二维数组new int[n][2],并将这些行视为成对.
Java没有内置Pair的几个原因类,但最引人注目的是,它是很容易写出具有相同功能的类,但有很多更多的启发,有帮助的名称为类,其字段,以及它的方法.
如果我们更多地了解您实际使用它的内容,我们可以提供更详细的建议 - 对于我们所知道的,Map这里可能是合适的.
| 归档时间: |
|
| 查看次数: |
30376 次 |
| 最近记录: |