问题描述
我有一些需要排序的键值对文件,值r
1306014503350001,0.7167574
1371031512360001,0.4335363
1371054509380001,2.3803377
1671046105520001,1.4315698
1810041005700002,0.030490799
1903034506620003,0.44315025
3171011804580003,0.72508544
3171015707400001,0.82567614
3171016009600004,0.44152263
3171077112400014,0.32794788
3171080502520003,0.46428326
3173010903500003,0.40578112
3173014203420002,0.67425823
3173015811550002,2.4808035
3174095204390002,0.9443519
3175036405300002,2.0835547
3175044211580002,0.3450352
需要根据comma(,)之后的值进行排序.根据dat整数值应进行b排序,但o/p应按i/p文件中的b进行排序,从某种意义上说,整数应b首先
I hav a file of some key value pairs need to sort,values r
1306014503350001,0.7167574
1371031512360001,0.4335363
1371054509380001,2.3803377
1671046105520001,1.4315698
1810041005700002,0.030490799
1903034506620003,0.44315025
3171011804580003,0.72508544
3171015707400001,0.82567614
3171016009600004,0.44152263
3171077112400014,0.32794788
3171080502520003,0.46428326
3173010903500003,0.40578112
3173014203420002,0.67425823
3173015811550002,2.4808035
3174095204390002,0.9443519
3175036405300002,2.0835547
3175044211580002,0.3450352
need to sort based on values after comma(,).According to dat integer values should b sorted but o/p should b as it is in i/p file in the sense integers should b first
推荐答案
c:\> sort input.txt > output.txt
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class validate2
{
private Map<double,> dataMap = null;
public static void main(String[] args) throws IOException {
String dataFileName = "E://abc1.txt";
Validate validate = new Validate();
validate.initializeData(dataFileName);
validate.printData();
}
public String getValue(Double key)
{
String value = null;
Long longValue = null;
if ((longValue=dataMap.get(key)) == null)
{
value = "value is null";
} else {
value = longValue.toString();
}
return value;
}
}
================================================== ============================
**这是我的工作,这是错误的,起初我需要获取整数值&稍后的float值**
306014503350001,0.7167574
1371031512360001,0.4335363
1371054509380001,2.3803377
1671046105520001,1.4315698
o/p应该以上述格式b进行aftr排序
================================================== ===========================
================================================================================
**this is my work, which is wrong,at first i need to get the integer values & later float values**
306014503350001,0.7167574
1371031512360001,0.4335363
1371054509380001,2.3803377
1671046105520001,1.4315698
o/p should b in above format aftr sorting
===============================================================================
这篇关于如何对值进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!