数据清洗小结

来源:互联网 发布:域名备案需要服务器吗 编辑:程序博客网 时间:2024/04/28 11:14

1、对于快速排序

    public static void QsortplusB(String[] arr, int low, int high) {        if (low >= high)            return;        int lt = low;        int gt = high;        String temp = arr[low];        int i = low + 1;        while (i <= gt) {            String s10[]=arr[i].split("----");            String s20[]=temp.split("----");                        if(s10.length==2 && s20.length==2){            String s1=s10[1];            String s2=s20[1];                        if (s1.compareTo(s2)<0) {//arr[i].hashCode() < temp.hashCode()                swap(arr, lt, i);                lt++;                i++;            } else if (s1.compareTo(s2)>0) {//arr[i].hashCode() > temp.hashCode()                swap(arr, gt, i);                gt--;            } else {                i++;            }        }            else{       //红色代码能规避错误。                System.out.println(arr[i]);                System.out.println(temp);//                System.out.println(i);                i++;            }        }                QsortplusB(arr, low, lt - 1);        QsortplusB(arr, gt + 1, high);    }

红色代码能规避错误。

2、根据制表 \t 和 , 切分

String  [] tokens=Pattern.compile("[\t,]").split(value.toString());
例:先去掉前两个,在根据\t ,切割
 String val="B:u3360,1  B:u39,1 B:u2730,1";           String [] kv=Pattern.compile("[\t,]").split(val.substring(2));           for(String k:kv){           System.out.println(k);           }

结果:

u33601  B:u391 B:u27301




0 0
原创粉丝点击