Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright (c) 2008-2010, Intel Corporation.
 * Copyright (c) 2006-2007, The Trustees of Stanford University.
 * All rights reserved.
 * Licensed under the terms of the New BSD License.
 */

import java.util.List;

public class Main {
    /**
     * Determines whether a given collection contains duplicate
     * values.
     *
     * @return true iff the given collection contains duplicate
     *       values.
     * @param   <T>   The type of the collection elements.
     * @param   elements   A collection.
     */
    public static <T> boolean hasDuplicates(final List<T> elements) {
        for (int i = 0; i < elements.size() - 1; i++) {
            final T element = elements.get(i);
            for (int j = i + 1; j < elements.size(); j++) {
                if (elements.get(j).equals(element))
                    return true;
            }
        }
        return false;
    }
}