Java 08: Advanced Arrays
Uploader Comments (gorilla3d)
Top Comments
-
Well, nice tutorial about how NOT TO use arrays in Java.
1., the worst thing you can do is to allocate memory for a larger array every time you want to add a new element to it. Have a look at the source code of the ArrayList class, and see that it operates on arrays behind the scenes. The best practice is to check whether there is enough space for the new element before you insert, and double the size once it is full.
2. java.util.Arrays.copy -- most cost-effective way of copying values
-
Minor thing.... you use the word "Integer" to describe your 'int array' there is a difference between 'int' and 'Integer'.... an 'int' is a primitive data type an 'Integer' is the wrapper clas that allows you to treat int's like objects not really that important but this differnce could confuse people if they go into the complexities of java programming
Video Responses
All Comments (35)
-
whereisthespacebar?
-
You do this and that and throw in some lightbulbs and Bam... Beautiful Explanation on how to use ARRAYs, but I still think I should look more into it
-
@JUanBOBO You are right..
-
why to you have to convert the array element into a String? i don't see the point because if you out put the integer it would still be 11.
-
@stedav WRONG! If you add to an array beyond it's specified size, you will get an ArrayIndexOutOfBounds runtime exception. Go learn java.
-
this motherfucker doesn't know anything, ha ha....
-
dude am soo confused
please explain
-
I am sorry, but I agree with most of the comments bellow. You just type and lack in explanation. =\
-
Don't just speak what you're typing. Explain what you're doing and why..what this video is, soforth. Come on, man.
-
BigE76 is absolutely correct, the confusion from this tutorial is evident. An int is a primitive type, and the Wrapper class Integer is an Object, with different behavior for each. The Wrapper class Integer has a default value of null, whilst the int is 0; this is a big difference in Arrays.t Further the size attribute in an array is a guide to the compiler about the minimum length, if you wish to add to the array you don't need to reassign the reference to a new array!
Netbeans is a great IDE so is Eclipse just a matter of taste.
gorilla3d 4 years ago