Storing number pairs in java

后端 未结 5 844
栀梦
栀梦 2021-01-17 11:54

How do I store a set of paired numbers in java? Do I use lists or arrays or maybe something else?

eg. [ (1,1) , (2,1) , (3,5)]

5条回答
  •  萌比男神i
    2021-01-17 12:48

    If you're needing to avoid duplicates then a HashSet would be a good choice but it not then an ArrayList would work.

    Class IntPair(){
      int i;
      int j;
    }
    HashSet set = new HashSet();
    

    or

    ArrayList list = new ArrayList();
    

提交回复
热议问题