List 中 存放 几百条数据 同搜索去处数据 怎么实现好些? 有个下拉框,当在下拉框输入搜索字符h时,下拉列表显示相应的item “hello” “head” 输入w item显示 “whree” “why” 输入 why 只显示 “why” 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用list的话也就是线性查找 如果有序的话用二分?为什么不在数据库查询非要拿到LIST再进行判断呢? <?xml version="1.0" encoding="utf-8" ?><commands> <command id="1" cmd="update_traffic"> <name>traffic1</name> <count control_type="text">21</count> <type control_type="combo" readonly="false"> <option id="1">aa</option> <option id="2">bb</option> </type> <enable control_type="checkbox" /> <help>hello update!</help> </command> <command id="2" cmd="start_traffic"> <name control_type="text">traffic2</name> <help>hello start!</help> </command> <command id="3" cmd="delete_traffic"> <name control_type="text">traffic3</name> <help>hello command!</help> </command> <command id="4" cmd="stop_traffic"> <name control_type="text">traffic4</name> <help>hello stop!</help> </command></commands>我是从XML中读取数据的 取出cmd放到list 如果是web程序的话,建议用js实现,不然太慢了 有人知道Eclipse 的 Combo 关于这方面的接口 或 三方控件 既然是CS,那直接在List中搜索就可以了(或转成String[]),监听值变化事件,每次在数组中循环查找。String的startsWith(String prefix) 方法即可。相信java的String处理,效率很高的。 最好还是存DB,万一下拉框的ITEM有变动呢? public static List<Attribute> getSortList(List<Attribute> list) { for (int i = 0; i < list.size(); i++) { for (int j = i + 1; j < list.size(); j++) { if (list.get(i).getValue().compareToIgnoreCase( list.get(j).getValue()) > 0) { // 忽略大小写 String t = list.get(i).getValue(); list.get(i).setValue(list.get(j).getValue()); list.get(j).setValue(t); } } } 我把List先排序了,SWT的Combo有查找的功能,不过在Combo输入什么只显示相应item 这个没实现。 JSON 表现 spring aop 设置一个advisor 和一个aspect 的冲突。 Ajax实现文件上传...怎么设置multipart/form-data Struts2 Action 失败后如何返回JAVASCRIPT代码 hibernate插入数据序列紊乱 hibernate分页问题! Java错误页面的处理 一段代码,感觉很恶心,求优化!! 高手请进,关于EJB的部署问题(100分相送) weblogic 下开发实体bean的问题 jsp报表导出excel文件 struts2文件上传问题
为什么不在数据库查询非要拿到LIST再进行判断呢?
<commands>
<command id="1" cmd="update_traffic">
<name>traffic1</name>
<count control_type="text">21</count>
<type control_type="combo" readonly="false">
<option id="1">aa</option>
<option id="2">bb</option>
</type>
<enable control_type="checkbox" />
<help>hello update!</help>
</command>
<command id="2" cmd="start_traffic">
<name control_type="text">traffic2</name>
<help>hello start!</help>
</command>
<command id="3" cmd="delete_traffic">
<name control_type="text">traffic3</name>
<help>hello command!</help>
</command>
<command id="4" cmd="stop_traffic">
<name control_type="text">traffic4</name>
<help>hello stop!</help>
</command>
</commands>我是从XML中读取数据的 取出cmd放到list
public static List<Attribute> getSortList(List<Attribute> list) {
for (int i = 0; i < list.size(); i++) {
for (int j = i + 1; j < list.size(); j++) {
if (list.get(i).getValue().compareToIgnoreCase(
list.get(j).getValue()) > 0) { // 忽略大小写
String t = list.get(i).getValue();
list.get(i).setValue(list.get(j).getValue());
list.get(j).setValue(t);
}
}
}
我把List先排序了,SWT的Combo有查找的功能,不过在Combo输入什么只显示相应item 这个没实现。