shweta patiljadhav wrote:Please give me an example of ArrayList of double and floats....I am able to create one with String and StringBuilder only....
As Paweł already mentioned you can't have an ArrayList with a primitive type. You can only have ArrayList with objects. Luckily for us, the Java API has for every primitive data type a primitive wrapper class (e.g. int -> Integer, float -> Float, and so on). So you must use the primtive wrapper class to create an ArrayList and you won't create an ArrayList of doubles/floats but you create an ArrayList of Doubles/Floats. Thanks to the autoboxing feature (which was added in Java 1.5), a primitive is automagically converted to an instance of the corresponding primitive wrapper class.
So let's turn all this boring text into some exciting code snippets Trying to create an ArrayList of primitive data types will not compileYou must use the corresponding primitive wrapper class, this code snippet compiles successfullyAnd thanks to autoboxing, primitive data types are automagically converted to an instance of the corresponding primitive wrapper class. So this code snippet will also compile successfully
But this code snippet has a compiler error. Do you know which line is causing this error and why?