我想比较这两个字符串和浮动compareTo
方法,但我不知道我的最终值将是什么。如何比较两个字符串和floatTo compareTo
下面是compareTo
的方法,我到目前为止执行:
ObjectClass otherObj = (ObjectClass)o;
float f1 = this.getValue();
float f2 = otherObj.getValue();
int retValue = Float.compare(f1,f2);
String code1 = this.getCode();
String code2 = otherObj.getCode();
int retValue2 = code1.compareTo(code2);
int finalRet = ??
return finalRet;
如果输入的是
hashMap.put(new ObjectClass ("20030122", 0.019f), "20030122");
hashMap.put(new ObjectClass ("20030123", 0.019f), "20030123");
hashMap.put(new ObjectClass ("20030124", 0.011f), "20030124");
我的输出应该在这个顺序
"20030123", 0.019f
"20030122", 0.019f
"20030124", 0.011f
什么语言呢? – Tyler
你期待什么结果?例如。如果比较“1.0,B”和“2.0,A”,这是“少于另一个”(以及为什么)? –
@Tyler:这是用Java编写的。 – user2500313