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};
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
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.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
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).
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Well, arrays of primitive types, not of some defined objects.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
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.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Mr.777 (November 14th, 2011)
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?
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
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.
Improving the world one idiot at a time!
KevinWorkman (November 15th, 2011), Mr.777 (November 14th, 2011)
Alright Kevin. Thanks. Well, atleast i got some new knowledge coz of you.
Thanks alot.
Thanks Junky.