Table like java data structure

前端 未结 7 1772
星月不相逢
星月不相逢 2020-12-03 01:14

I need to implement some kind table-like data structure that stores info like this in Java:

+--------+-------+-----+
|  sij   |   i   |  j  |
+--------+-----         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 01:43

    If I understand your question right, all you need is a Comparable class to represent a row.

    public static class Row
    implements Comparable {
      public Row(int sij, int i, int j) {
        this.sij = sij;
        this.i = i;
        this.j = j;
      }
    
      public int compareTo(Row other) {
        return Integer.valueOf(sij).compareTo(other.sij);
      }
    
      public final int sij;
      public final int i;
      public final int j;
    }
    

    You can then populate a List with instances of Row and use Collections.sort to sort it.

提交回复
热议问题