Arrays, String and Other String Class
Arrays, String and Other String Class
Module Objective
Arrays Define an array. Explain single - dimension array Describe two dimension array
String
Other String class
FPT- APTECH
2/33
#1 - Array
Introduction to Arrays Array declaration Initializing Array Elements Accessing Array Elements
FPT- APTECH
3/33
Introduction to Arrays
Special data store that can hold several items of a single data type in contiguous memory location. All the elements within an array must belong to the same data type. Arrays are zero indexed An array with n elements is indexed from 0 to n-1. Array in Java is Object
FPT- APTECH
4/33
Array declaration
Declaring an array variable does not create an array! You must use new to explicitly create the array instance The default value of numeric array elements are set to zero, and reference elements are set to null.
FPT- APTECH
5/33
Array dimension
FPT- APTECH
6/33
The elements of an array can be explicitly initialized You can use a convenient shorthand
FPT- APTECH
7/33
FPT- APTECH
8/33
Types of Arrays
FPT- APTECH
9/33
Single-Dimensional Arrays
Have only one dimension and is visually represented as having several row but a single column of data.
FPT- APTECH
10/33
Store elements : Initialize individual array elements Use Loop to initialize Access elements: Using Loop for..each loop (JDK 1.5)
FPT- APTECH
11/33
FPT- APTECH
12/33
FPT- APTECH
13/33
FPT- APTECH
14/33
#2 - String class
Describe String Methods of String class Describe String array and its use Describe command line arguments in Java and its use
FPT- APTECH
15/33
String class
The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of String class. Strings are constant Values cannot be changed after they are created. String objects are immutable they can be shared.
FPT- APTECH
16/33
FPT- APTECH
17/33
FPT- APTECH
18/33
Common-used methods
FPT- APTECH
19/33
String Arrays
FPT- APTECH
20/33
String arguments
FPT- APTECH
21/33
A Java application can accept any number of arguments from the operating system command line. The purpose is to specify the configuration information for the application. The parameter of the main() method is a String array that represents the command-line arguments.
FPT- APTECH
22/33
FPT- APTECH
23/33
FPT- APTECH
24/33
StringBuilder class
A mutable sequence of characters. String objects are immutable sequence of characters Character or String can be inserted in the StringBuilder object and they can also be appended at the end.
FPT- APTECH
25/33
FPT- APTECH
26/33
FPT- APTECH
27/33
FPT- APTECH
28/33
StringTokenizer class
Allows an application to break a string into tokens The set of delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis.
FPT- APTECH
29/33
FPT- APTECH
30/33
FPT- APTECH
31/33
FPT- APTECH
32/33