|
查看: 1502|回复: 7
|
Java - Sort & Remove Duplicate in Array
[复制链接]
|
|
|
如题。我要的结果是012,要如何做?谢谢!
String r = "1021";
char[] content = r.toCharArray();
Arrays.sort(content);
String result = new String(content);
out.print("Result:" + result); |
|
|
|
|
|
|
|
|
|
|
发表于 1-12-2009 09:05 AM
|
显示全部楼层
String r = "1021";
String sortString = "";
HashMap HostCount = new HashMap();
for (int i = 0; i < r.length(); i++) {
HostCount.put(r.charAt(i), r.charAt(i));
}
Set HostKeys = HostCount.keySet();
Iterator It = HostKeys.iterator();
while (It.hasNext()) {
Character HostNow = (Character)It.next();
sortString += "" + HostCount.get(HostNow);
}
System.out.println ("SortString : " + sortString);
不过 我 RETUNR 回 210 。。。 LZ 自己 SORT 。。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2009 12:17 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2009 01:15 PM
|
显示全部楼层
对不起。为什么有Warning的?
warning: [unchecked] unchecked call to put (K, V) as a member of the raw type java.util.HashMap
我把 HashMap HostCount = new HashMap(); 改成HashMap HostCount<String, String> = new HashMap<String, String>(); 都不能。请帮忙,谢了。 |
|
|
|
|
|
|
|
|
|
|
发表于 1-12-2009 01:23 PM
|
显示全部楼层
- HostCount.put(r.charAt(i), r.charAt(i));
复制代码
注意type |
|
|
|
|
|
|
|
|
|
|
发表于 1-12-2009 03:41 PM
|
显示全部楼层
原帖由 mikeng 于 1-12-2009 01:15 PM 发表 
对不起。为什么有Warning的?
warning: unchecked call to put (K, V) as a member of the raw type java.util.HashMap
我把 HashMap HostCount = new HashMap(); 改成HashMap HostCount = new HashMap(); 都不 ...
不用 DECLARE PARAMETER 的 。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 1-12-2009 04:04 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 25-4-2010 11:09 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|