60 likes | 209 Views
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.
E N D
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) {}
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 • ArrayList • LinkedList • List interface
Collection: ArrayList • ArrayList (java.util package) • ArrayList<String> list1 = new ArrayList<String>(); • Methods: size, get, add(with/without index), remove, clear
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()