3 Arrays
3 Arrays
By
Manjiri Tatke
Objectives
• After completing this lesson, participants
will be able to
• Understand the different types of Arrays
• Implement one and multi dimensional arrays
• Iterate arrays using loops
• Use varargs
• Work with java.util.Arrays
Arrays
• Arrays are used to group elements of either of primitive or reference types
• Array in java is created as Object:
• This object will help developers to find size of array
• Using this object developers can manipulate array
• Can be compared with null
• All elements of array of same type
• Array is a fixed-length data structure having zero-based indexing
Arrays
• A group of like-typed variables referred by a common name
• Array declaration and initialization:
• int arr [];
arr = new int[10];
• int arr[] = {2,3,4,5};
• int twoDim [][] = new int[4][5];
Creating Array Objects
• Arrays of objects too can be created:
Box barr[] = new Box[3];
• Example 1: barr[0] = new Box();
barr[1] = new Box();
barr[2] = new Box();