Java List from Array asList(Object value)

Here you can find the source of asList(Object value)

Description

as List

License

Open Source License

Declaration

public static List asList(Object value) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;
import java.util.Arrays;

import java.util.Collections;
import java.util.Enumeration;

import java.util.List;

public class Main {
    public static List asList(Object value) {
        if (value == null) {
            return Collections.EMPTY_LIST;
        } else if (value instanceof List) {
            return (List) value;
        } else if (value.getClass().isArray()) {
            return Arrays.asList((Object[]) value);
        } else if (value instanceof Enumeration) {
            List answer = new ArrayList();
            for (Enumeration e = (Enumeration) value; e.hasMoreElements();) {
                answer.add(e.nextElement());
            }/*w ww.j a va  2 s  .  co  m*/
            return answer;
        } else {
            // lets assume its a collection of 1
            return Collections.singletonList(value);
        }
    }
}

Related

  1. asList(long... array)
  2. asList(Object info)
  3. asList(Object o, Class cls)
  4. asList(Object theone)
  5. asList(Object value)
  6. asList(Object[] array)
  7. asList(Object[] array)
  8. asList(Set set)
  9. asList(String data)