Friday, April 26, 2013

Java Dynamic Arrays

As you may know, arrays in Java are not dynamic by default, so you will have to implement ways to make them that yourself. You CAN change the elements in an array but you CAN'T change the size ( add or remove ) elements after the array has been initialized. In this post I will show you how to change arrays dynamically by using some methods.



But at first, a little introduction to arrays in Java.



























The code outputs as follows:





A method that transform a given array into an array without "null" elements.




Now let's try it out

















And it outputs:



Now how to add the elements into an array that is already full.



















And let's try it out
We get the following output





The source code can be downloaded from ( here )

No comments:

Post a Comment