1 / 6

Array in Java

This guide covers essential concepts of arrays and collections in Java, focusing on both one-dimensional and multidimensional arrays. Learn how to declare and initialize arrays, access their elements, and determine their lengths. Additionally, explore Java's collection framework, including ArrayLists and LinkedLists, highlighting key methods like add, remove, and clear. The tutorial features practical examples to illustrate the functionality of these data structures, making it perfect for beginners and those looking to refresh their knowledge of Java programming.

kyrie
Télécharger la présentation

Array in Java

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. Array in Java • Array, element, index(or subscript) • int[] a = new int[12]; • int[] a = {31, 28, 31, 30, 31, 30 31, 31, 30, 31, 30, 31}; • a[0], a[1],…, and a[11] • a.length • String[] d = {“Sun”, “Mon”, Tue”, “Wed”, “Thu”, “Fri”, “Sat”}; • public static void main(String[] args) {}

  2. Array in Java • Multidimensional array • int[][] b = new int[4][3]; • int[][] b = {{1, 2, 3}, {4, 5, 6} {7, 8, 9}, {0, 1, 2}}; • b[0][0], b[0][1],…, b[3][2] • b[0], b[1], b[2], b[3] • b.length(the number of rows), b[0].length,…, b[3].length

  3. Collections in Java • Generic Collections • ArrayList • LinkedList • List interface

  4. Collection: ArrayList • ArrayList (java.util package) • ArrayList<String> list1 = new ArrayList<String>(); • Methods: size, get, add(with/without index), remove, clear

  5. Collection: LinkedList • LinkedList(java.util package) • List<String> list2 = new LinkedList<String>(); • Interface: List (search interface list in java) • Iterator: ListIterator<String> itr =list2.listIterator(); • itr.hasNext(), itr.next(), itr.hasPrevious(), itr.previous()

  6. Examples

More Related