- Arraylist is a class that inherits the List interface
- To define a list --->
ArrayList<String> groceryList = new ArrayList();
groceryList.add("apples");
- To print items from a list
groceryList.get(i)
- To change value at a particular index in list
groceryList.set(1,"kiwis");
- To remove an item as well as the index from the list
groceryList.remove(1);
- To check if a particular item is there in the list
groceryList.contains("apples");
- To find the index no of an item in the list
groceryList.indexOf("apples")
- Arraylist can't handle primitive data types like integers,floats ,doubles etc. It can only handle classes like String. And for primitive data types
- Instead we use wrapper classes for primitive data types likes Integer Double etc.
- Then we add retrieve values like this
integerList.add(Integer.valueOf(i*20));
System.out.println(integerList.get(i).intValue());
//Or simply like this as wrapping is done by java by itself in the background
integerList.add(i * 10);
System.out.println(integerList.get(i));