arraylist java example
Example 1: arraylist methods in java
ArrayList<String> filteredColors = (ArrayList<String>) colors.stream().filter(x -> x.contains("o")).collect(Collectors.toList());
filteredColors = (ArrayList<String>) colors.clone();
filteredColors.removeIf(x -> !x.contains("o"));
colors.stream().filter(x -> x.contains("ora")).findFirst().get();
Example 2: how to create a list in java
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
class scratch{
public static void main(String[] args) {
List<Integer> aList = new ArrayList<>();
List<Integer> lList = new LinkedList<>();
}
}
Example 3: java arraylist
import java.util.List;
import java.util.ArrayList;
List l = new ArrayList();
ArrayList a = new ArrayList();
List<String> l = new ArrayList<String>();
ArrayList<Integer> a = new ArrayList<Integer>();
List<Double> l = new ArrayList<Double>(5);
Example 4: arraylist in java
import java.util.ArrayList;
public class ArrayListExample
{
public static void main(String[] args)
{
int num = 14;
ArrayList<Integer> al = new ArrayList<Integer>(num);
for(int a = 1; a <= num; a++)
{
al.add(a);
}
System.out.println(al);
al.remove(7);
System.out.println(al);
for(int a = 0; a < al.size(); a++)
{
System.out.print(al.get(a) + " ");
}
}
}
Example 5: arraylist java
import java.util.ArrayList;
import java.util.*
ArrayList<DataType> name = new ArrayList<DataType>();
Example 6: arraylist
ArrayList<String>arrayList=new ArrayList<>();