找寻丢失的Id

来源:互联网 发布:java class命名规范 编辑:程序博客网 时间:2024/04/28 22:05

简述:

从源sIds组生成目标dIds组过程中找寻丢失的Id


代码:

public static void main(String[] args) {List<String> sIds = Arrays.asList(new String[]{"b", "a", "c", "e", "d", "g", "f"});List<String> dIds = Arrays.asList(new String[]{"b", "e"});Collections.sort(sIds);Collections.sort(dIds);final int sSize = sIds.size();final int dSize = dIds.size();// 丢失Id的集合List<String> lostIds = new ArrayList<String>();int sIndex = 0, dIndex = 0;while(sIndex < sSize && dIndex < dSize){String sId = sIds.get(sIndex);String dId = dIds.get(dIndex);if(sId.compareTo(dId) < 0){lostIds.add(sId);}else{dIndex++;}sIndex++;}for(int i = sIndex; i < sSize ; i++){String sId = sIds.get(i);lostIds.add(sId);}System.out.println(lostIds.toString());}




输出:







1 0