Question:
Java what is the default type of the ArrayList if i dont specifiy?
2011-10-09 13:04:05 UTC
when i write that code the compiler doesnt give an error,also it is acceptable also what is the type of the myInstance(i.e Integer,String,or Object type?) and what is the default capacity of ArrayList if we dont explicitly specify?

[code]
ArrayList myInstance=new ArrayList ( );
[/code]
Three answers:
Silent
2011-10-09 13:13:41 UTC
If you don't specify a type, you're using the old non-generic version. This would basically be equivalent to:



ArrayList myInstance = new ArrayList();



The capacity of an ArrayList created with the no-argument constructor is 10.
?
2017-01-15 13:22:58 UTC
ArrayList shops products of any type. you are able to keep products of different training. once you retrieve an merchandise you will ought to solid it into the class which you somewhat choose. If those products are by some potential logically appropriate, it must be a extra advantageous concept to create a sort with those values as fields. then you definitely could build an merchandise, placing the fields, and merely keep the unmarried merchandise. additionally, keep in mind that int is a primative. you are able to ought to apply a 'wrapper' type. enable's say you have int num = 6; to make an merchandise of the Integer type: Integer numObj = new Integer(6);
modulo_function
2011-10-09 13:37:04 UTC
Correct but don't confuse capacity with size.



Although you get an initial capacity of 10 with the default constructor, the size, of course, is 0.



The user rarely needs to be concerned with capacity.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...