Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Adds the element parameter only if it isn't inside yet.
     *
     * @param aList
     *         The {@link List} to fill.
     * @param element
     *         The element to add to the aList parameter.
     */
    public static void addWhenNecessary(List aList, Object element) {
        if (aList == null) {
            aList = new ArrayList();
            aList.add(element);
            return;
        }

        if (!aList.contains(element)) {
            aList.add(element);
        }
    }
}