What is the equivalent of the C++ Pair in Java?

前端 未结 30 1077
一个人的身影
一个人的身影 2020-11-22 02:29

Is there a good reason why there is no Pair in Java? What would be the equivalent of this C++ construct? I would rather avoid reimplementing my own.<

30条回答
  •  灰色年华
    2020-11-22 03:08

    For programming languages like Java, the alternate data structure used by most programmers to represent pair like data-structures are two array, and data is accessed via the same index

    example: http://www-igm.univ-mlv.fr/~lecroq/string/node8.html#SECTION0080

    This isn't ideal as the data should be bound together, but also turn out to be pretty cheap. Also, if your use case demands storing co-ordinates then its better to build your own data structure.

    I've something like this in my library

    public class Pair{.. }
    

提交回复
热议问题