Declare an ArrayList named taxRates of * five *elements of type Double and initialize the elements (starting with the first) to the values 0.10 , 0.15 , 0.21 , 0.28 , 0.31 , respectively.
I tried:
double taxRates[5] = {0.10, 0.15, 0.21, 0.28, 0.31};
Printable View
Declare an ArrayList named taxRates of * five *elements of type Double and initialize the elements (starting with the first) to the values 0.10 , 0.15 , 0.21 , 0.28 , 0.31 , respectively.
I tried:
double taxRates[5] = {0.10, 0.15, 0.21, 0.28, 0.31};
That's an array, not an ArrayList.
What does that mean?
An ArrayList is an Object that holds a variable amount of other Objects.
An array is a container that holds a fixed number of Objects or primitives.
They aren't the same, and what you've supplied doesn't match your title, so some clarification is necessary.
Additional to Kevin's answer: Well, in easy words though:)
1. Arrays are non resizable
2. Arrays store only single data type values(Say Elements).
3. ArrayLists are resizable.
4. ArraLists can store multi data type values(Say Objects).
Well, arrays of primitive types, not of some defined objects.
Like I said, arrays definitely CAN contain primitives, but they don't HAVE to. They con contain Objects as well. So to say the can only contain a single data type is not correct. I don't want to be pedantic, but the OP seems extremely confused already, so I don't want to confuse him even more.
Oh yeah if this is the fact then yes arrays can have multiple types. So, ignore the point, Arrays can store only single type elements.
So Kevin, don't you think, elements and objects are different things?
Yes that is fine. What Kevin is questioning is the following statement made by you:
2. Arrays store only single data type values
Which is incorrect! Arrays can most certainly hold elements of different data types as long as they are subclasses of a superclass. Just as Kevin demonstrated above
Bah! Page 2.
Alright Kevin. Thanks. Well, atleast i got some new knowledge coz of you.
Thanks alot.
Thanks Junky.