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?
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.