1 / 11

Java Arrays

Java Arrays. By Srinivas Reddy.S. www.java9s.com. Arrays. Collection of similar data types Stages Declaration Construction Initialization. www.java9s.com. Declaration. Declaring Arrays: int[] marks; byte[] age; Less readable: int marks[]; byte age[];. www.java9s.com.

andie
Download Presentation

Java Arrays

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 Arrays By Srinivas Reddy.S www.java9s.com

  2. Arrays • Collection of similar data types Stages • Declaration • Construction • Initialization www.java9s.com

  3. Declaration • Declaring Arrays: int[] marks; byte[] age; Less readable: int marks[]; byte age[]; www.java9s.com

  4. Construction int[] marks; marks = new int[5]; “The size of the array is mandatory” In single line: int[] marks = new int[5]; marks www.java9s.com

  5. Initialization • Initialization is loading the array with the values. int[] marks = new int[5]; marks[0] =20; marks[1]=49; marks[2] =30; marks[3] = 67; marks[4] = 35; 20 49 30 67 35 0 1 2 3 4 www.java9s.com

  6. Initialization – Objects class Pen{ } Pen[] pens = new Pen[3]; pens[0] = new Pen(); Pens[1] = new Pen(); Pens[2] = new Pen(); 0 1 2 www.java9s.com

  7. Array Initializer. • int[] marks ={20,39,40,30}; Array Initializer www.java9s.com

  8. Two dimensional Array • int[][] marks = new int[2][3]; marks[0][0] = 30; marks[0][1]=31; marks[0][2]=32; marks[1][0]=40; marks[1][1]=41; marks[1][2]=42; 1 0 1 2 1 2 0 0 31 40 41 42 32 30 www.java9s.com

  9. Two dimension- non uniform • int[][] marks = new int[2]; • marks[0] = new int[3]; • marks[1] = new int[4]; 1 0 1 2 0 0 1 2 3 www.java9s.com

  10. Multidimensional Arrays • int[][][] marks = new int[2][3][2]; 1 0 1 2 1 2 0 0 0 1 0 1 0 1 0 1 0 1 0 1

  11. www.JAVA9S.com

More Related