Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

import java.util.List;
import java.util.Locale;

import java.util.Vector;

public class Main {
    public static <T> List<T> uniqueList(List<T> list) {
        Vector<T> v = new Vector<T>();
        for (T obj : list) {
            if (!v.contains(obj)) {
                v.add((T) obj);
            }
        }
        return v;
    }

    /**
     * Check if the list contains the member. For objects, it uses standard .equals() method. 
     * For strings, it compares but ignores the case.
     * 
     * @param list
     * @param member
     * @return
     */

    public static boolean contains(List<? extends Object> list, Object member) {
        if (list.isEmpty() || member == null)
            return false;

        for (Object obj : list) {
            if (obj instanceof String && member instanceof String) {
                if (compareIgnoreCase((String) obj, (String) member))
                    return true;
            } else {
                if (member.equals(obj))
                    return true;
            }
        }

        return false;
    }

    public static boolean compareIgnoreCase(String str1, String str2) {
        return str1.toLowerCase(Locale.ENGLISH).equals(str2.toLowerCase(Locale.ENGLISH));
    }
}