

Both Array and ArrayList can hold duplicates and multiple null elements. You can insert ArrayList or delete it in any particular position.
#Array vs arraylist iin java code
The code above uses a method in ArrayList contains(). The result of the code will be the folowing: The students list has name that contains Juliet (“No name Juliet in the list of Students”) (“The students list has name that contains Juliet”)

Here’s a sample code using ArrayList contains():īoolean student_names = ntains(“Juliet”) Student’s names are alphabetically arranged.Īnother notable usage of ArrayList using contains()method, in which it uses a search algorithm where the specified element exists in the list given. The output was slightly different from the previous example. You can sort the name of students alphabetically by adding Collections.sort(variable_name) to the code above. In this code, I use Java Collection class under the java.util package. Using the general format above, here’s an example of how a one-dimensional array is being implemented.
