如何在J2me中搜索和排序(升序或降序)
我想知道如何在 J2ME 中进行搜索。我一直在互联网上搜索,向我展示了很多结果,我在 Java2s.com 中看到我得到了一个使用 RecordFilter
和匹配方法在记录存储中搜索的结果。
但我的问题是,当我需要向其中传递 2 个或更多参数时。结果如何与这些参数匹配?
如何像冒泡排序一样进行降序或升序排序?
I am wondering about how to search in J2ME. I have been searching in the internet, so many result show to me, and I see in Java2s.com I got a result use RecordFilter
and matches method for search in record store.
But my problem is, when I need to pass 2 or more parameters into it. How can result matches with these parameter?
And how to sort descending or ascending like bubble sort?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将搜索连接到单个字符串变量中。例如,用
;
将它们分开。在matches
方法的代码中分解字符串以获取每个搜索条件。要使过滤器生效,请创建 SearchFilter 的实例并使用连接字符串作为其参数调用
matches
方法。对于
sort
,实现RecordComparator
接口;实现compare
方法来构建排序标准。在 google 上搜索 j2me+recordcomparator 以查看有关如何进行排序的示例。编辑:
在
matches
方法的代码中分解从byte[]参数获得的String参数。对待每个分解的字符串来制定标准。据我了解,您在编写时希望传递两个字符串作为搜索条件:
所以在构造函数中应该有两个参数!
当你想要进行匹配时,调用
if searchFilter.matches((search1+";"+sType).getBytes())
然后将
candidate
参数分解为两个 String您编写matches
方法。Concatenate your searches into a single String variable. Separate each of them with
;
for example. In the code of thematches
method explode the String to get each search criteria.To make the filter in effect create an instance of SearchFilter and call the
matches
method with the concantenated String as its param.For the
sort
implement theRecordComparator
interface ; implement thecompare
method to build your sort criteria. Make a google search about j2me+recordcomparator to see examples about how to make sorts.EDIT :
In the code of the
matches
method explode the String param obtained from the byte[] param. Treat each String exploded to make the criteria.As I understand you want to pass two string as a search criteria when you wrote :
So in the constructor there should be two params !!!
When you want to make the matching then call
if searchFilter.matches((search1+";"+sType).getBytes())
Then explode the
candidate
param into two String when you code thematches
method.当我将数据保存在 RMS 中时,我将其保存为 String[],就像我想保存每个员工的姓名、年龄、薪水、EmpID 一样,我将其保存创建一个数组并将其转换为字节并将其保存在 RMS 中。当我检索它时,我会执行相反的过程。现在,如果我想获得姓名以 A 开头且薪水 10000 的员工,我使用以下过滤器
这样我可以过滤任何参数。希望有帮助! :)
When I save my Data in RMS I save it as a String[] like I want to save Name, Age,Salary,EmpID for each employee I save it create an array and convert it to bytes and save it in RMS. When i retrieve it i do the reverse process. Now if i want to get employee with names starting with A and with salary 10000 i use the following filter
This way i can filter any no of parameters.Hope tht helps! :)