找寻丢失的Id

简述:

从源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());
	}




输出:





扫描二维码关注公众号,回复: 3832289 查看本文章



猜你喜欢

转载自blog.csdn.net/anialy/article/details/40106537
id