Urgenthomework logo
UrgentHomeWork
Live chat

Loading..

Java Strings Homework Help

Java Strings

The sequence of characters is called strings. In java provides strings as a class to manipulating functions.

Creating strings:

String s1=”hai”;

String length:

The length method is used to find the length of the particular string.

Example:

Output:

String Length is : 15

Concatenating strings:

It is used to concatenate the two strings.

Example:

Output:

my name is mani

String methods:

There are many methods are available for manipulating strings using string class.

1. Char charAt(int i) – return ith index character

“welcome”.charAt(4); result c

2. String substring (int i) – return substring from ith index

“welcome”.substring(5); result me

3. String substring (int I, int j) – return substring from ith index to jth index

“welcome”.substring(2,5); result lco

4. Int indexOf(string s) – return index of string first occurrence

String s =” my name is mani”

Int o= s.indexOf(“mani”); result 11

5. Int lastindexOf(string s) – return index of string last occurrence

String s =” my name is mani”

Int o= s.indexOf(“n”); result 13

Like that many string methods are available in java.

Copyright © 2009-2023 UrgentHomework.com, All right reserved.