【发布时间】:2013-01-15 12:24:15
【问题描述】:
我有这个数组存储用户正在添加的一些 URL 的后缀:
[U2, U3, U1, U5, U8, U4, U7, U6]
当我这样做时:
for (Map<String, String> map : getUrlAttachments()) {
String tmpId = map.get("id"); //it receives the U2, in the 1st iteration, then U3, then U1,...
if (tmpId.charAt(0) == 'U') {
tmpId.charAt(1);//2, then 3, then 1,...
String url = map.get("url");
String description = map.get("description");
URLAttachment attachment;
String cleanup = map.get("cleanup");
if (cleanup == null && url != null && description != null) {
attachment = new URLAttachmentImpl();
attachment.setOwnerClass(FileUploadOwnerClass.Event.toString());
attachment.setUrl(url);
attachment.setDescription(description);
attachment.setOwnerId(auctionHeaderID);
attachment.setUrlAttachmentType(URLAttachmentTypeEnum.EVENT_ATTACHMENT);
attachment.setDateAdded(new Date());
urlBPO.save(attachment);
}
我的问题:
我想通过传递另一个列表来更改此For 条件,该列表映射按[U1, U2, U3, U4, U5, U6, U7, U8] 排序的数据。
我希望您能帮助我了解最好的方法。
我想过创建一个列出 id 的数组然后排序,但我不知道如何在 java 中准确地对字母数字字符串进行排序。
【问题讨论】:
-
看看TreeMap。