在Excel中制作过滤系统的最佳逻辑是什么?

时间:2014-02-03 23:11:20

标签: algorithm user-interface

我有一个列表字符串数组来保存表格数据,我们先知道有2个字段Item&价格:

String[] myArr1={"car","12014"};
String[] myArr2={"book","120"};
String[] myArr3={"chair","500"};
String[] myArr4={"car","510"};
String[] myArr5={"book","50"};

以上所有String数组都应放入List。

然后我想创建一个类似于Excel的过滤系统,例如,当用户点击Item列时,Panel将弹出&看起来像这样:


Exter Text:_____ (a textbox that user can type in data & the List should show 
only rows that match that data)

(A List of check boxes of ALL UNIQUE text in the Item column, if user 
uncheck then all the rows that contain that data will be removed, just like in Excel.)

[x] Car
[x] Book
[x] Chair

这个问题与特定语言无关,因为我只想知道构建这个系统的逻辑。逻辑应该优雅,简单,完善和优雅;易于编码。

1 个答案:

答案 0 :(得分:1)

我个人会在列的值中存储一个包(Java Set)。 Java中的LinkedHashSet将按输入的顺序存储它们,因此您可以按字母顺序排列值。这将是关于列中值的元数据。

这样做的好处是Set可以快速访问,并且只允许使用唯一值,因此您的唯一值列表不会以与列中值相同的速率增长(除非所有值都是如此)是独一无二的)

相关问题