下拉列表中出现的值的顺序发生变化
我有一个按数字和字母顺序排序的值数组列表。例如。该列表的值(按相同顺序)如 1, 2, 5, 10, 100, A012B, AB, XY, Z。
我使用 for 循环将此列表添加到 StringBuffer 中,并将 Stringbuffer 对象作为字符串返回(通过 sbf.toString() ),因为我的方法只能返回 String 类型(根据方法声明)。我无法更改返回类型(它必须是字符串,因为我的框架只接受字符串类型)。
返回的值显示在下拉列表中。但值的顺序正在改变,并显示为 1, 10, 100, 2, 5, A012B, AB, XY, Z。我希望这些值以与数组列表中相同的方式显示。你能帮忙吗?
I have an arraylist of values that are sorted both numerically and alphabetically. For eg. the list has values(in same order) like 1, 2, 5, 10, 100, A012B, AB, XY, Z.
Im adding this list to a StringBuffer using a for loop and returning the Stringbuffer object as a string (via sbf.toString()
) since my method can return only String type (as per method declaration). I cannot change the return type (it has to be a String since my framework accepts only String type).
The values that are returned are displayed in a dropdown. But the order of values is getting changed and being displayed like 1, 10, 100, 2, 5, A012B, AB, XY, Z. I want the values to be displayed in the same fashion that they were present in the arraylist. Can you help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将数据添加到下拉列表的代码似乎正在对数据进行排序。如何创建下拉列表?这是 Swing 应用程序还是 Web 应用程序?在某些网络框架中,下拉列表会自动排序,在这种情况下您必须禁用该默认设置。
StringBuffer 不会自动对字符串进行排序,因此这不是问题。要对此进行测试,请在将 StringBuffer 内容添加到列表之前将其输出到命令行。
The code that is adding data to the dropdown appears to be sorting the data. How do you create the dropdown list? Is this a Swing application or a web application? In some web-frameworks, dropdown lists are automatically sorted and you have to disable that default in this case.
StringBuffer will not sort a string automatically, so that can't be the problem. To test this, output the StringBuffer contents to the command-line just before adding it to the list.