java文本处理常用代码总结(二)

来源:互联网 发布:regretted it 编辑:程序博客网 时间:2024/05/17 05:10

一、使用命令行调用java程序

main函数中(//java从0命令行输入,而python从1)sys.argv[1]

        Integer threadcount=Integer.parseInt(args[0]);String file_in=args[1];String file_out=args[2];excute_in_main(threadcount, file_in,file_out);
java中字典按值排序

[java] view plain copy
  1.  List<Entry<String,Integer>> list =new ArrayList<Entry<String,Integer>>(dicHashMap.entrySet());  
  2.  Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {  
  3.              public int compare(Map.Entry<String, Integer> o1,  
  4.                   Map.Entry<String, Integer> o2) {  
  5.                  return (o2.getValue() - o1.getValue());  
  6.              }  
  7.          });  
  8.      for (Entry<String,Integer> i: list){  
  9.          writerdic.write(i.getKey()+"\t"+i.getValue()+"\n");  
  10.      }  

上述代码是讲map中的value按照逆序排序,如果需要按照升序进行排序的话,只需要修改o2.getValue() - o1.getValue()为o1.getValue() - o2.getValue()即可




0 0
原创粉丝点击