Java Array Duplicate deleteDuplicatedPages(int[] pages)

Here you can find the source of deleteDuplicatedPages(int[] pages)

Description

Transforms (0,1,2,2,3) to (0,1,2,3)

License

Open Source License

Declaration

public static int[] deleteDuplicatedPages(int[] pages) 

Method Source Code

//package com.java2s;
/**/*  www. ja  v  a  2  s.  co m*/
 * Copyright 2014 Joan Zapata
 *
 * This file is part of Android-pdfview.
 *
 * Android-pdfview is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Android-pdfview is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Android-pdfview.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.ArrayList;
import java.util.List;

public class Main {
    /** Transforms (0,1,2,2,3) to (0,1,2,3) */
    public static int[] deleteDuplicatedPages(int[] pages) {
        List<Integer> result = new ArrayList<Integer>();
        int lastInt = -1;
        for (Integer currentInt : pages) {
            if (lastInt != currentInt) {
                result.add(currentInt);
            }
            lastInt = currentInt;
        }
        int[] arrayResult = new int[result.size()];
        for (int i = 0; i < result.size(); i++) {
            arrayResult[i] = result.get(i);
        }
        return arrayResult;
    }
}

Related

  1. addNoDuplicate(String[] array, String target)
  2. arrayDuplicate(byte[] in)
  3. duplicateArrayEntries(String[] inputArr, int numDuplicates)
  4. eraseDuplicatedValue(String[] srcArr)
  5. hasDuplicates(final T[] array)
  6. isDuplicated(String[] strArray)