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

design an lru cache in java?

936


What is <> used for in java?

1069


What does java stand for?

1039


What is string in java?

960


What is the exact difference in between Unicast and Multicast object?

2042


What do you mean by stream pipelining in java 8?

1154


Does java isempty check for null?

943


What is a loop java?

1004


What is definition and declaration?

964


What is difference between hashset and hashmap?

1052


What is the use of arraylist class in java?

1007


How does indexof work?

892


Can java program run without jre?

958


How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?

1043


Write code to implement bubble sort in java?

943