0

Which is the best way in Java 8 to get a List with elements of Type1 from a List of Lists -> (Records) {List<Type1>, List<Type2>, List<Type3>, ...} ?

Records has several Lists with different Types -> {List<Type1>, List<Type2>, List<Type3>, ...}

List<T> getList(T t) {
  // t is instance of Type1
  return Records -> List<t>;
}

Thanks so much for your help.

2
  • are Type1, Type2 etc related? Commented Oct 23, 2017 at 16:22
  • No, the Types are fully independent from each other. Thanks for your comment. Commented Oct 23, 2017 at 16:47

1 Answer 1

1
class Utils<T> {

    List<T> getList(T t, List<List> list) {
        return list.stream().filter(i -> t.getClass().isInstance(i.get(0))).flatMap(List<T>::stream).collect(Collectors.toList());
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.