Arrays and Collections Arrays One dimensional array Two Slides: 7 Download presentation Arrays and Collections • Arrays – One dimensional array – Two or multiple dimensional array • Collections – Array. List – Linked. List Array in Java • Array, element, index(or subscript) • int[] a = new int[12]; • int[] a = {31, 28, 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) {} 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 Collections in Java • Generic Collections • Array. List • Linked. List • List interface Collection: Array. List • Array. List (java. util package) • Array. List<String> list 1 = new Array. List<String>(); • Methods: size, get, add(with/without index), remove, clear Collection: Linked. List • Linked. List (java. util package) • Linked. List< String > list 1 = new Linked. List< String >(); • List<String> list 2 = new Linked. List<String>(); • Interface: List (search interface list in java) • Iterator: List. Iterator<String> itr =list 2. list. Iterator(); • itr. has. Next(), itr. next(), itr. has. Previous(), itr. previous() An Example A circular motion is one dimensionalIn the statement "int *arr[4];",arr isC++ cli listOne dimensional arrayOne dimensional arrayTwo dimensional array pythonHaskell two dimensional arrayDeclare a two dimensional array of strings named chessboard