Java Array Duplicate addNoDuplicate(String[] array, String target)

Here you can find the source of addNoDuplicate(String[] array, String target)

Description

add No Duplicate

License

Apache License

Declaration

public static String[] addNoDuplicate(String[] array, String target) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;
import java.util.List;

public class Main {
    public static String[] addNoDuplicate(String[] array, String target) {
        List<String> list = Arrays.asList(array);
        if (!list.contains(target)) {
            list.add(target);/*  ww w  .j  av  a  2 s .  c o  m*/
        }
        String[] result = list.toArray(new String[0]);
        return result;
    }
}

Related

  1. arrayDuplicate(byte[] in)
  2. deleteDuplicatedPages(int[] pages)
  3. duplicateArrayEntries(String[] inputArr, int numDuplicates)
  4. eraseDuplicatedValue(String[] srcArr)