Java List Flatten flatten(List input)

Here you can find the source of flatten(List input)

Description

flatten

License

Open Source License

Declaration

public static ArrayList<?> flatten(List<?> input) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static ArrayList<?> flatten(List<?> input) {
        ArrayList<Object> result = new ArrayList<Object>();
        for (Object o : input) {
            if (o instanceof List<?>) {
                result.addAll(flatten((List<?>) o));
            } else {
                result.add(o);/*from w  w w. j  a va2 s  .  c o  m*/
            }
        }
        return result;
    }
}

Related

  1. flatten(List> list)
  2. flatten(List list, List flat)
  3. flatten(List> nested)
  4. flatten(List>... deeps)
  5. flatten(List l)

  6. HOME | Copyright © www.java2s.com 2016