java 兩個數組相減結果


	public static void main(String[] args) {
		String[] a = new String[] { "1", "5", "3", "7" };
		String[] b = new String[] { "1", "5" };
		String[] arrResult = arrContrast(a, b);
		for (String strResult : arrResult) {
			System.out.println("最后的結果:----------->" + strResult);
		}
	}

	// 處理數組字符
	private static String[] arrContrast(String[] arr1, String[] arr2) {
		List<String> list = new LinkedList<String>();
		for (String str : arr1) { // 處理第一個數組,list里面的值為1,2,3,4
			if (!list.contains(str)) {
				list.add(str);
			}
		}
		for (String str : arr2) { // 如果第二個數組存在和第一個數組相同的值,就刪除
			if (list.contains(str)) {
				list.remove(str);
			}
		}
		String[] result = {}; // 創建空數組
		return list.toArray(result); // List to Array
	}

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM