Java
Create an array list of your own choosing; the data type is up to you. Add at least four values to it initially. Then, insert at least two values. Display the value of the first and last items using the get method. Replace at least one value with a new value. Display the final count of items in the array list.
#source code in java:
import java.util.*;
public class demo_program{
public static void main(String args[]){
ArrayList<Integer> data = new ArrayList<Integer>();
//intially add 4 items;
data.add(4);
data.add(3);
data.add(5);
data.add(6);
System.out.println(data);
//then insert 2 values;
data.add(8);
data.add(9);
System.out.println("First item: "+data.get(0));
System.out.println("Last item: "+data.get(5));
System.out.println(data);
//change the value in the Arraylist
data.set(2,25);
System.out.println(data);
System.out.println("Arraylist size is Here:"+data.size());
}
}
#output:
#if you have any doubt or more information needed comment below....i will respond as possible as soon..thanks...
Get Answers For Free
Most questions answered within 1 hours.