1 / 6

Array in Java

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”};

kyrie
Download Presentation

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