CH.
09: Java Array, String
& Utility Class
Intro to Array:
Arrays in Java store multiple values of the
same data type in one variable.
Arrays are objects that can hold a fixed
number of elements and each element of
array has an index number (starts from 0)
used to access it.
Types of Array:
(1) 1-Dimension Array
(2) 2-Dimension Array
(3) Multi Dimension Array
(4) String Array
Conti…
1 Developed By … Rupesh Sir @Dholakiya Schools : Rajkot - Gondal
(1) 1-D Array: 1-D Array Elements are
accessed using a single row, single index,
starting from 0.
Ex. int value[] = {90, 85, 92};
[Link](value[0]);
1-D Array Elements (Having Single Index):
Index | Value
[0] = 90
[1] = 85
[2] = 92
(2) 2-D Array: 2-D Array Elements are
accessed using row and column, multiple
indexes.
Ex. int value[][] = {{11, 12}, {13, 14}};
[Link](value[0][0]);
2-D Array Elements (Having Multiple Indexes):
2×2 matrix (2 rows and 2 columns)
Index | Value/Element | Row (1st Index) | Column (2nd Index)
[0][0] = 11 0 0
[0][1] = 12 0 1
[1][0] = 13 1 0
[1][1] = 14 1 1
2 Developed By … Rupesh Sir @Dholakiya Schools : Rajkot - Gondal
(3) Multi Dimension Array: Multi-D Array
Elements are accessed using multiple rows and
columns, multiple indexes.
Ex.
int value[][][] = {{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}};
// 1x3x3 matrix
[Link](value[0][0][0]);
// Prints '11', the element at block 0, row 0, column 0
3-D Array Elements (Having Multiple Indexes):
Index | Value/Element | Block (1st Index)| Row (2nd Index) | Column (3rd Index)
[0][0][0] = 1 0 0 0
[0][0][1] = 2 0 0 1
[0][0][2] = 3 0 0 2
[0][1][0] = 4 0 1 0
[0][1][1] = 5 0 1 1
[0][1][2] = 6 0 1 2
[0][2][0] = 7 0 2 0
[0][2][1] = 8 0 2 1
[0][2][2] = 9 0 2 2
(4) String Array: In Java, a String array is a data
structure that stores a fixed-size collection
of String objects.
Ex.
String[] weekdays = {"Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"};
Conti…
3 Developed By … Rupesh Sir @Dholakiya Schools : Rajkot - Gondal
-:Java Utility Class / Package / Library:-
import [Link]
(Statement to import Date library in Java)
No. Method Description
1. Date() Constructs Date object using current time
2. Date (long Constructs Date object using specified time
elapsed time) in milliseconds
3 toString() Returns date & time in string
representation
4. getTime() Returns number of milliseconds
5. setTime() Sets new date and time
import [Link]
(Statement to import Calendar library in Java)
No. Constant Description
1. YEAR Returns Year of calendar
2. MONTH Returns Month of Calendar
(0 for January, 11 for December)
3 DATE Returns day of calendar month
4. HOUR Returns hour in 12 hour notation
5. MINUTE Returns Number of Minutes
6. SECOND Returns Number of Seconds
7. AM_PM 0 for AM, 1 for PM
8. DAY_OF_WEEK 1 for Sunday, 7 for Saturday
9. WEEK_OF_MONTH Returns week number within month
10. WEEK_OF_YEAR Returns week number within year
11. DAY_OF_YEAR Day number in the year (1 for first day)
----------
4 Developed By … Rupesh Sir @Dholakiya Schools : Rajkot - Gondal