LoginSignup
1
3

More than 5 years have passed since last update.

〘JAVA〙配列の重複項目を削除する(HashSet不使用)

Posted at
    public static void main(String[] args) {

        int arrayA[] = new int[5];
        arrayA[0] = 10;
        arrayA[1] = 11;
        arrayA[2] = 12;
        arrayA[3] = 13;
        arrayA[4] = 14;

        int arrayB[] = new int[5];
        arrayB[0] = 11;
        arrayB[1] = 11;
        arrayB[2] = 11;
        arrayB[3] = 11;
        arrayB[4] = 12;

        ArrayList arrayC = new ArrayList();

        for (int i = 0; i < arrayA.length; i++) {
            for (int j = 0; j < arrayB.length; j++) {
                if (arrayA[i] == arrayB[j]) {
                    arrayC.add(arrayA[i]);
                    break;
                }
            }
        }

        System.out.println(arrayC);

    }
1
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3