Question: public class ArrayListOperations { public static void main ( String [ ] args ) { / / a . Add and display the following elements
public class ArrayListOperations
public static void mainString args
a Add and display the following elements in the ArrayList object: Google, Apple, Amazon, Facebook, Twitter, and Oracle.
ArrayList companies new ArrayList;
companies.addGoogle;
companies.addApple;
companies.addAmazon;
companies.addFacebook;
companies.addTwitter;
companies.addOracle;
System.out.printlnInitial list of companies:";
for String company : companies
System.out.printlncompany;
b Update the rd element in the above list by Microsoft
companies.set "Microsoft"; Arrays are zeroindexed, so rd element is at index
System.out.println
List after updating the rd element to 'Microsoft':";
for String company : companies
System.out.printlncompany;
c Remove the last element from the list of objects.
companies.removecompaniessize;
System.out.println
List after removing the last element:";
for String company : companies
System.out.printlncompany;
d Check whether an element is available on the list.
String elementToCheck "Facebook";
boolean isAvailable companies.containselementToCheck;
System.out.println
Is elementToCheck available in the list? isAvailable;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
