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

11&12 java

The document contains Java programs demonstrating various methods of the String and StringBuffer classes, including operations like length, substring, concatenation, and manipulation methods. Additionally, it includes a program that implements user-defined packages, showcasing how to create and import a package. The document is structured with practical exercises and outputs for each program.

Uploaded by

Priyanka Thadke
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

11&12 java

The document contains Java programs demonstrating various methods of the String and StringBuffer classes, including operations like length, substring, concatenation, and manipulation methods. Additionally, it includes a program that implements user-defined packages, showcasing how to create and import a package. The document is structured with practical exercises and outputs for each program.

Uploaded by

Priyanka Thadke
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Name :Amanwad Vishnukant .

v class:CO4I’A’

ROLLNO:13

PRACTICAL NO:11&12.

Aim: performing Program for all methods of string class.

public class Demo { public static void main(String[] args)

String str = "vishnukant";

System.out.println("Length of the string: " + str.length());

System.out.println("Character at index 7: " + str.charAt(7));

System.out.println("Substring from index 2 to 7: " + str.substring(2, 7));

String str2 = " Amanwad";

System.out.println("Concatenated string: " + str.concat(str2));

System.out.println("Index of 'o' in the string: " + str.indexOf('o'));

System.out.println("Last index of 'o' in the string: " + str.lastIndexOf('o'));


System.out.println("Does the string start with 'Hello'? " + str.startsWith("Hello"));
System.out.println("Does the string end with 'World!'? " + str.endsWith("World!"));

String str3 = "Hello, World!";

System.out.println("Are str and str3 equal? " + str.equals(str3));

String str4 = "HELLO, world!";

System.out.println("Are str and str4 equal ignoring case? " + str.equalsIgnoreCase(str4));

System.out.println("Lowercase string: " + str.toLowerCase());

System.out.println("Uppercase string: " + str.toUpperCase());

String str5 = " vishnu ";

System.out.println("Trimmed string: " + str5.trim());

System.out.println("Replacing 'o' with 'x': " + str.replace('o', 'x'));

String[] words = str.split(",");


System.out.println("Splitting the string: ");

for (String word : words) {

System.out.println(word.trim());

System.out.println("Does the string contain 'World'? " + str.contains("World"));

Output:

Q2.Program for all methods of stringbuffer class.

public class Demo2 { public static void

main(String[] args) {
StringBuffer stringBuffer = new StringBuffer("Hello");

stringBuffer.append(" World");

System.out.println("After append(): " + stringBuffer);

stringBuffer.insert(5, ", ");

System.out.println("After insert(): " + stringBuffer);

stringBuffer.delete(5, 8);

System.out.println("After delete(): " + stringBuffer);

stringBuffer.deleteCharAt(5);

System.out.println("After deleteCharAt(): " + stringBuffer);

stringBuffer.reverse();

System.out.println("After reverse(): " + stringBuffer); System.out.println("Capacity of


StringBuffer: " + stringBuffer.capacity());

System.out.println("Length of StringBuffer: " + stringBuffer.length());


stringBuffer.setLength(5);

System.out.println("After setLength(): " + stringBuffer);

System.out.println("Character at index 2: " + stringBuffer.charAt(2));

System.out.println("Substring from index 1 to 3: " + stringBuffer.substring(1,3));

stringBuffer.replace(1, 3, "XYZ");

System.out.println("After replace(): " + stringBuffer);

stringBuffer.ensureCapacity(50);

System.out.println("After ensureCapacity(): " + stringBuffer);

}
Name :Amanwad Vishnukant . V class:CO4I’A’

ROLLNO:13

PRACTICAL NO:20

AIM: write a program to implement user defined packages in terms of creating a

new package and importing the same package vishnu; public class Tr

public void display()

System.out.println("it is vishnukant package");


}

SOURCE FILE:

import vishnu.Tr; class

Pr

public static void main(String args[])

Tr u=new Tr();

u.display();

OUTPUT:

You might also like