1 / 24

Java ArrayList Tutorial | Java ArrayList Examples | Java Tutorial For Beginners | Edureka

( ** Java Certification Training: https://www.edureka.co/java-j2ee-soa-training ** ) <br>This Edureka tutorial on u201cJava ArrayListu201d (Java blog series: https://goo.gl/osrGrS) will give you a brief insight about ArrayList in Java and its various constructors and methods along with an example. Through this tutorial, you will learn the following topics: <br><br>Collections Framework <br>Hierarchy of ArrayList <br>What is ArrayList <br>Internal Working of ArrayList <br>Constructors of ArrayList <br>Constructors Example <br>ArrayList Methods <br>Methods Example and Demo <br>Advantages of ArrayList over Arrays <br><br>Check out our Java Tutorial blog series: https://goo.gl/osrGrS <br>Check out our complete Youtube playlist here: https://goo.gl/CRbgFann <br><br>Follow us to never miss an update in the future. <br><br>Instagram: https://www.instagram.com/edureka_learning/ <br>Facebook: https://www.facebook.com/edurekaIN/ <br>Twitter: https://twitter.com/edurekain <br>LinkedIn: https://www.linkedin.com/company/edureka

EdurekaIN
Download Presentation

Java ArrayList Tutorial | Java ArrayList Examples | Java Tutorial For Beginners | Edureka

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training

  2. Topics For Today’s Discussion Collections Framework 01 02 Hierarchy of ArrayList Class 03 ArrayList in Java 04 Internal Working of ArrayList 05 Constructors of ArrayList Methods of ArrayList 06 07 Benefits of ArrayList vs Arrays JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training

  3. Collections Framework

  4. Iterable Collection Set Queue List Priority Queue HashSet ArrayList Deque LinkedHashSet LinkedList SortedSet Vector ArrayDeque Stack TreeSet

  5. Hierarchy of Array List Class Iterable extends Collection extends List implements Abstract List extends ArrayList

  6. ArrayList in Java ArrayList is a part of collection framework present in java.util package. It provides dynamic arrays in Java. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training

  7. Internal Working of ArrayList Array List Initialization myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] Adding elements to Array List myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] Capacity of Array List is Full myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] Creating a new array & moving the elements to new array myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] myArray[0] myArray[1] myArray[2] myArray[3] myArray[4] Size is increased to double JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training

  8. Constructors of ArrayList ArrayList( ) ArrayList(Collection c) ArrayList(int Capacity) JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training

  9. Constructors of ArrayList ArrayList( ) This constructor builds an empty array list. Syntax: ArrayList(Collection c) ArrayList<E> myArray = new ArrayList<E>(); ArrayList(int Capacity) JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training

  10. Constructors of ArrayList ArrayList( ) This constructor builds an array list that is initialized with the elements of the collection c. ArrayList(Collection c) Syntax: public boolean addAll(Collection c) ArrayList(int Capacity) JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training

  11. Constructors of ArrayList ArrayList( ) It is used to build an array list that has the specified initial capacity. Syntax: ArrayList(Collection c) ArrayList myArray = new ArrayList(int initialCapacity); ArrayList(int Capacity) JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training

  12. Methods of Arraylist

  13. void add(int index, Object element) void clear( ) This method is used to insert a specific element at a specific position index in a list. void trimToSize() Example: Int indexOf(Object O) ArrayList<String> al=new ArrayList<String>(); Object clone() al.add(“Jino"); Object[] to Array() al.add(“Piyush"); Object remove(int index) al.add(“Pramod"); Int size()

  14. void add(int index, Object element) This method is used to remove all the elements from any list. void clear( ) Example: void trimToSize() ArrayList<String> al=new ArrayList<String>(); Int indexOf(Object O) al.add("abc"); Object clone() al.add("xyz"); System.out.println("ArrayList before clear: "+al); Object[] to Array() al.clear(); Object remove(int index) System.out.println("ArrayList after clear: "+al); Int size()

  15. void add(int index, Object element) The trimToSize() method in Java trims the capacity of an ArrayList instance to be the list’s current size. This method is used to trim an ArrayList instance to the number of elements it contains. void clear( ) Example: void trimToSize() Int indexOf(Object O) ArrayList<Integer> al = new ArrayList<Integer>(9); al.add(2); al.add(4); al.add(5); Object clone() Object[] to Array() al.trimToSize(); System.out.println("The List elements are:"); Object remove(int index) Int size()

  16. void add(int index, Object element) This method returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. void clear( ) void trimToSize() Example: Int indexOf(Object O) ArrayList<Integer> al = new ArrayList<Integer>(9); al.add(2); al.add(4); al.add(5); Object clone() Object[] to Array() int pos = al. indexOf(3); Object remove(int index) Int size()

  17. void add(int index, Object element) Returns a shallow copy of this ArrayList. void clear( ) Example: void trimToSize() ArrayList<String> al=new ArrayList<String>(); Int indexOf(Object O) Object cloneList; //Added 2 elements al.add("abc"); al.add("xyz"); Object clone() System.out.println("Elements are: "); Object[] to Array() cloneList = al.clone(); System.out.println("Elements in cloneList are:"); Object remove(int index) Int size()

  18. void add(int index, Object element) Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that of the specified array. void clear( ) void trimToSize() Example: Int indexOf(Object O) arrayList.add("element_1"); arrayList.add("element_2"); arrayList.add("element_3"); arrayList.add("element_4"); Object clone() Object[] to Array() Object[] objArray = arrayList.toArray(); Object remove(int index) Int size()

  19. void add(int index, Object element) java.util.ArrayList.remove(Object) method removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged. void clear( ) void trimToSize() Example: Int indexOf(Object O) arrayList.add(“J"); arrayList.add(“I"); arrayList.add(“N"); arrayList.add(“O"); Object clone() Object[] to Array() arraylist.remove(“N”); Object remove(int index) Int size()

  20. void add(int index, Object element) It returns the number of elements in this list i.e the size of the list. void clear( ) void trimToSize() Example: Int indexOf(Object O) Declaration: public int size() Object clone() arrayList.add(“J"); arrayList.add(“I"); arrayList.add(“N"); arrayList.add(“O"); Object[] to Array() Object remove(int index) int asize = arraylist.size(); Int size()

  21. Advantages of ArrayList Over Array ArrayList is Variable length Allows to add duplicate elements Size can be modified dynamically Can traverse in both directions Insert & Remove elements at particular position Can add any type of data in arraylist JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training

More Related