0% found this document useful (0 votes)
75 views

Arrays, String and Other String Class

This document discusses arrays, strings, and other string classes in Java. It covers defining and initializing single and multi-dimensional arrays, common string methods, using string arrays and command line arguments, and the StringBuilder and StringTokenizer classes. The StringBuilder class allows mutable string operations while the StringTokenizer class breaks strings into tokens.

Uploaded by

Phuong Le
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Arrays, String and Other String Class

This document discusses arrays, strings, and other string classes in Java. It covers defining and initializing single and multi-dimensional arrays, common string methods, using string arrays and command line arguments, and the StringBuilder and StringTokenizer classes. The StringBuilder class allows mutable string operations while the StringTokenizer class breaks strings into tokens.

Uploaded by

Phuong Le
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

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

The number of indexes associated with each element

FPT- APTECH

6/33

Initializing Array Elements

The elements of an array can be explicitly initialized You can use a convenient shorthand

FPT- APTECH

7/33

Accessing Array Elements

Supply an integer index for each dimension Indexes are zero-based

FPT- APTECH

8/33

Types of Arrays

Single - Dimensional Arrays Multi - Dimensional Arrays (matrix, arrays 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

Working with Single-Dimensional Arrays

Store elements : Initialize individual array elements Use Loop to initialize Access elements: Using Loop for..each loop (JDK 1.5)

FPT- APTECH

11/33

Example of Working with Single-Dimensional Arrays

FPT- APTECH

12/33

Multidimensional Arrays, (matrix, arrays of arrays)

<data type> [ ] [ ] <array name> = new <data type> [ rows][cols]

FPT- APTECH

13/33

Working with Multidimensional Arrays

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

Create a String Object

FPT- APTECH

17/33

Example of Using String class

FPT- APTECH

18/33

Common-used methods

FPT- APTECH

19/33

String Arrays

FPT- APTECH

20/33

String arguments

The parameter of the main() method represents the command-line arguments.

FPT- APTECH

21/33

String Command Line Arguments

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

Example of String Command Line Arguments

FPT- APTECH

23/33

#3 - Other String class

StringBuilder class StringTokenizer class

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

Constructors of StringBuilder class

FPT- APTECH

26/33

Methods of StringBuilder class

FPT- APTECH

27/33

Example of StringBuilder class

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

Constructor of StringTokenizer class

FPT- APTECH

30/33

Method of StringTokenizer class

FPT- APTECH

31/33

Example of Using StringTokenizer class

FPT- APTECH

32/33

Thats about all for today!

Array String class StringBuilder class StringTokenizer class

Thank you all for your attention and patient!

You might also like