[Go to site: main page, start]

0% found this document useful (0 votes)
2 views4 pages

Java Program For String Functions

The document provides a Java program demonstrating various string functions such as length, toUpperCase, toLowerCase, concat, charAt, equals, compareTo, indexOf, substring, and replace. It also includes a StringBuffer example showcasing methods like append, insert, replace, delete, reverse, length, and capacity. The output of each operation is printed to illustrate the functionality of these string and StringBuffer methods.
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)
2 views4 pages

Java Program For String Functions

The document provides a Java program demonstrating various string functions such as length, toUpperCase, toLowerCase, concat, charAt, equals, compareTo, indexOf, substring, and replace. It also includes a StringBuffer example showcasing methods like append, insert, replace, delete, reverse, length, and capacity. The output of each operation is printed to illustrate the functionality of these string and StringBuffer methods.
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

JAVA PROGRAM FOR STRING FUNCTIONS

(length, toUpperCase, toLowerCase, Concat, charAt,


equals, compareTo, indexOf, substring, replace)

public static void main(String[] args)


{

String str1 = "Java";


String str2 = "Programming";

// length()
[Link]("Length of str1 = " + [Link]());

// toUpperCase()
[Link]("Uppercase = " +[Link]());

// toLowerCase()
[Link]("Lowercase = " + [Link]());

// concat()
[Link]("Concatenation = " + [Link](" " + str2));

// charAt()
[Link]("Character at index 2 = " +[Link](2));
// equals()
[Link]("str1 equals Java = " + [Link]("Java"));

// compareTo()
[Link]("Compare = " +[Link]("Java"));

// indexOf()
[Link]("Index of 'a' = " + [Link]('a'));

// substring()
[Link]("Substring = " + [Link](0, 4));

// replace()
[Link]("Replace = " + [Link]('a', 'o'));
}
}
Output
Length of str1 = 4
Uppercase = JAVA
Lowercase = programming
Concatenation = Java Programming
Character at index 2 = v
str1 equals Java = true
Compare = 0
Index of 'a' = 1
Substring = Prog
Replace = Jovo

2. StringBuffer Methods

public class StringBufferDemo {


public static void main(String[] args) {

StringBuffer sb = new StringBuffer("Java");

[Link]("Original : " + sb);

[Link](" Programming");
[Link]("Append : " + sb);

[Link](4, " Language");


[Link]("Insert : " + sb);

[Link](0, 4, "Python");
[Link]("Replace : " + sb);
[Link](6, 15);
[Link]("Delete : " + sb);

[Link]();
[Link]("Reverse : " + sb);

[Link]("Length : " + [Link]());


[Link]("Capacity : " + [Link]());
}
}

You might also like