Yup that is an array as here are the diferences Array is static, arraylist is dynamic Array contains primitive data types while arraylist does not (its kinda mix) Arraylist is like this ArrayList arraylistobject = new ArrayList(); //no static size arraylistobject.add(16); // uses the word add to add things arraylistobject.add("I'm handsome");
Its like a box where you divide its inside space so that you can throw muliple items inside. lol troll here no idea
If it's Java, I believe ArrayList is an implementation of a list/collection based on an array. As such, it's basically just a wrapper class that manages all the resizing and insertion/removal from an array for you. You said you don't understand it, but that's far too vague a statement. It doesn't really help people know what you need help with. Well, here's more details I guess. I'm hoping you know how basic arrays work, meaning the ones defined using brackets [], because I'm gonna be explaining based on that premise. When you declare an array, you should be aware that you first create a reference to that array, like int[] thisIsAnArray; creates a reference to an array of integers. Since you haven't initialized it yet, it's just null, so you have to initialize it with thisIsAnArray = new int[10]; which creates a new integer array of size 10, which thisIsAnArray now points to. The concept is similar with an ArrayList or any other class. ArrayList<Integer> thisIsAnArrayList; creates a reference to an ArrayList of integers. I would explain why you put the type of list it is within <>, but that's a more advanced concept that you will probably learn later. For now, just know that that's where you put what you want to store in your ArrayList. Now, you need to initialize the ArrayList. thisIsAnArrayList = new ArrayList<Integer>(); Now thisIsAnArrayList points to an empty ArrayList of integers. To add things to the ArrayList, you use the add method. thisIsAnArrayList.add(5); Now your ArrayList contains a 5. Comparing this to arrays, this would be thisIsAnArray[0] = 5; Storing 5 at index 0 in the array. The difference between ArrayLists and arrays is that ArrayLists manage the indexes for you. If you use the add function, it will add a new value at a not yet used index. After adding whatever you need to the ArrayList, you probably want to look at it. With arrays, to access the value you just need to do thisIsAnArray[0] and that will give you the value in your array at index 0. In an ArrayList, you have to use the get method, which takes an index and returns the value at the index. thisIsAnArrayList.get(0) will return the value at index 0 of the list, which will again, return 5. There's more, but I'm bored of typing.
It was in novel discussion. You have asked for help but nothing specific what about the concept do you not understand? @Teddywonka and @Alchyr have given good descriptions. After reading those post what you do not understand about what they have said. http://stackoverflow.com/ is a really good resource to search for help. There you need to search before asking a question.
Actually with Java 8, I believe when you instantiate the arraylist, you don't need the second reference of the object type. It would look like this: thisIsAnArray= new ArrayList<>();
Technically that's probably legal, but it's always better to be clear. I mean, technically you can use Objects to store almost everything, but that's probably not a good idea. Yes that's a really bad comparison, but I think you get the idea.
You only need to put it the first time when you create the reference. You no longer need to put it twice
The way I learned to do it is List<> name = new ArrayList<>(); This takes advantage of polymorphism. I don't use Java much as I prefer c++ and c#. Java and c# are very similar I just like the features and IDE (Visual Studio) of c#
Basically the same as lists, but different area of use due to different implementation (hence it is specified as arraylist and not linked list or whatever) Don't get confused by the prefix 'array'. That is just to enable users to identify the different implementations of lists. It's just a list.