Hey guys I am learning and playing with ArrayList, I was able to create a basic ArrayList. I would like to accomplish the following: I was trying different methods but couldn't get it.
- Get only Integer objects:
- Get only String Objects
- Get only even Integer objects
- Get Integer and Double Objects.
- Get all String Objects starts with "S".
- Get all String Objects which contains a.
======================= Here is my program =========================
import java.io.Serializable;
import java.util.*;
public class ArrayListDemo1 {
public static void main(String[] args) {
ArrayList al = new ArrayList();
System.out.println("Before = " + al.size());
al.add(10);
al.add(43);
al.add(32.5);
al.add(10);
al.add(null);
al.add('A');
al.add("ABC");
al.add(10.12);
al.add(true);
al.add("Hello");
al.add(600);
al.add(900);
// System.out.println(al);
// System.out.println("After = " + al.size());
// System.out.println(al instanceof Cloneable); //true
// System.out.println(al instanceof Serializable); //true
// System.out.println(al instanceof RandomAccess);
// System.out.println(al instanceof List);
// System.out.println(al instanceof Collection);
// System.out.println(al instanceof Set);
// ArrayList<Integer> a1 = al;
// System.out.println(a1);
}
}
Stream.filter, e.g.al.stream().filter(entry -> …).…ArrayListexpects one generic type argument to be given, but you are providing none. This only compiles because of backward-compatibility. You should provide a type argument.