Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What will be the output of the program?

public class Test {
public static void main(String args[]) {
ArrayList<String> list = new ArrayList<String>();
list.add("2");
list.add("3");

list.add("4");
list.add("5");
System.out.println("size :"+list.size());
for(int i=0;i<list.size();i++) {
list.remove(i);
}
System.out.println("size after:"+list.size());
}
}

Answer Posted / qim2010

The final Output is
size :4
Size after:2

While called ArrayList.remove() method, in remove method, we
can pass object or index number to remove.

// remove array list element by index number
list.remove(2); //will remove the second element

// remove ArrayList element by Object value
list.remove("2"); //will remove the element

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we call a non-static method from inside a static method?

990


How an object is serialized in java?

980


What is difference between static and final?

1066


Explain super keyword in java.

1028


What is executor memory?

939


How to compare strings in java?

993


What are namespaces in java?

1027


What are autoboxing and unboxing? When does it occur?

944


How do you use substring in java?

1124


What is the difference between yielding and sleeping?

1100


can rmi and corba based applications interact ?

1074


What is Enum in Java?

1293


Can we override constructor?

1016


How to restrict a member of a class from inheriting by its sub classes?

1337


What are the types of java languages?

972