ch9 Array
ch9 Array
[TI
1-D array
t Array with single dimension is known as 1-D array.
t Example : Vector
t Instead of declaring individual variables like
markl, mark2, mark3, mark4, markS
we declare array mark[S]
t Index Position : mark[0],mark[1],mark[2],mark[3],mark[4]
tTo declare a 1-D array we use a pair of square brackets [ ].
t Syntax:<data type><array name>[ ]; Example : int marks[ ];
CT]
To declare 1-D array
int marks[ ] = new int [SJ;
- - ----
tHere,
marks= name of array.
[I]
Example : 1-D array
tThe array variable martls has an index I•~=i,t,A.\'-\ ltl;I
value from Oto 4.
. . Amy Amy
t marks[O] refers to the first element. ldatact C. Wti
t marks[4] refers to the last element.
t 1-D array is initialized using comma RMftct
VnNt
separated values of data element In
braces { }.
t Example : Int marks[ J = {90, 60, 70, 65, 80};
[TI
2-D array
t Array with two dimension Is known as 2-D array.
t 2-D arrays are used to store tabular data In the form of
rows and columns.
t Example : To store 5 student's marks in 3 tests, we may
use a tabular arrangement of marks 5 rows and 3 columns.
St•d~nts Tesll Testl Tes&J
I ~o 60 70
2 3S 30 so
3 70 1S 80
4 80 85 90
s 40 so 55
[TI
t In Java, 2-0 array can be declared using array name and
two pairs of square brackets [ ] [ ] to specify the size of
two dimensions row and column respectively.
V,u ·fablt-
Rderence
\ ·11ri11bles
[TI
Points to be remembered
...,,,,-it Array Is a collection of homogeneous type of data.
~ r a y elements can be accessed using Index for each
dl_menslon In [ ].
00
String class methods
t String class provides methods for below tasks :
• Compare string
• Find length of string
• Combining strings
• Obtaining substrings
• Converting strings
• Splitting strings
• Searching for character or patterns In string
Date class
Date object using current system
(1) Date()
time
Number of milliseconds since 1,
(2) Long getTime()
Janua 1970 GMT
Date Specified time In milliseconds
(3) elapsed since 1, January 1970
(long elapsedTime) GMT (GMT : Greenwich Mean Time)
(4) String toString() Representing date and time
void setTime
(5) Sets new date and time
(long elapsedTime)
calendar class
Year of calendar
MONTH Month of calendar (O-Jan, 11-Dec)
DATE Day of calendar month.
(4) DAY_OF_MONTH Same as DATE.
(5) HOUR Hour in 12-hour notation
(6) HOUR_OF_DAY Hour in 24-hour notation
(7) MINUTE Minute
(8) SECOND Second
~
(9) AM_PM 0 for AM and 1 for PM
Day number within a week
Sun-1 ..... Sat-7
) WEEK_OF_MONTH Week number within the month
WEEK_OF_YEAR Week number within the year
DAY_OF_YEAR Day number In the year 1 for 1st day
t Date class/ Cal_e ndar class provided In java.utll package.
t Date class encapsulate both date and time and represents
the value using milliseconds precision.
tCalendar store year, month, date, hour, minute, second.