Posts

Showing posts with the label List in Java

ArrayList in Java

An ArrayList is a group of common elements. It is concrete implementation of List interface. ArrayList has ordered elements in which order they added. There are several methods which we will discuss here today. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 package net . raj . test ; import java.util.ArrayList ; import java.util.List ; public class ArrayListImpl { public static void main ( String [] args ) { // Declare an ArrayList List < string > list = new ArrayList <>(); list . add ( "one" ); list . add ( "two" ); list . add ( "three" ); list . add ( "four" ); System . out . println ( "Sample ArrayList 1:: " + list . toString ()); } } Output: Sample ArrayList 1:: [one, two, three, four] In the above example we saw that we added few elements when print those items we saw the same order in which they added to list. It shows the basic property ...