0% found this document useful (0 votes)
29 views5 pages

56 Tanay JAVA Exp7

Hhh

Uploaded by

Deadly Ninja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views5 pages

56 Tanay JAVA Exp7

Hhh

Uploaded by

Deadly Ninja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment No.

7
String Operations

Name: Tanay More Date: 14/10


Roll No. 56 Batch G3

Aim: a. WAP to count number of occurrences of given character using string class.

b. WAP to count no of vowels using string class.

Theory:

In java, string is basically an object that represents sequence of char values. An array of
characters works same as java string.
The java.lang.String class provides a lot of methods to work on string. By the help of these
methods, we can perform operations on string such as trimming, concatenating, converting,
comparing, replacing strings etc. Java String is a powerful concept because everything is
treated as a string if you submit any form in window based, web based or mobile application.
In java, string objects are immutable. Immutable simply means unmodifiable or unchangeable.
Once string object is created its data or state can't be changed but a new string object is
created.
Java String class methods
The java.lang.String class provides many useful methods to perform operations on sequence of
char values.

In java, string objects are immutable. Immutable simply means unmodifiable or

unchangeable. Once string object is created its data or state can't be changed but a new string

object is created. Java String class methods

The java.lang.String class provides many useful methods to perform operations on sequence of
char values.

No. Method Description

1 char charAt(int index) returns char value for the particular index

2 int length() returns string length

3 String substring(int returns substring for given begin index


beginIndex)

4 String substring(int returns substring for given begin index and end
beginIndex, int index
endIndex)
5 boolean equals(Object checks the equality of string with object
another)
6 boolean isEmpty() checks if string is empty
7 String concat(String str) concatinates specified string
8 String replace(char old, replaces all occurrences of specified char value
char new)
9 String replaces all occurrences of specified
replace(CharSequence CharSequence
old, CharSequence new)
10 String trim() returns trimmed string omitting leading and
trailing spaces
11 String intern() returns interned string
12 int indexOf(int ch) returns specified char value index
13 int indexOf(int ch, int returns specified char value index starting with
fromIndex) given index
14 int indexOf(String returns specified substring index
substring)
15 int indexOf(String returns specified substring index starting with
substring, int fromIndex) given index
16 String toLowerCase() returns string in lowercase.
17 String toUpperCase() returns string in uppercase.
18 String trim() removes beginning and ending spaces of this
string.

PROGRAM/CODE: a

SIES GRADUATE SCHOOL OF Page 2


TECHNOLOGY
OUTPUT a

Program Code: b

SIES GRADUATE SCHOOL OF Page 3


TECHNOLOGY
Output b

Conclusion:
We implemented string class operations to calculate occurences of vowels and a given character in a string.

SIES GRADUATE SCHOOL OF Page 4


TECHNOLOGY
SIES GRADUATE SCHOOL OF Page 5
TECHNOLOGY

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy