0% found this document useful (0 votes)
40 views1 page

A Val Val1 Val3 Val2 Val Val1 Val Val2 Val Val2 Val Val Val3 Val Val Val Val Val1 Val Val Val Val Val Val

This Java code demonstrates various string methods in Java including ==, equals(), length(), charAt(), toLowerCase(), concat(), replace(), substring(), indexOf(), and lastIndexOf(). It creates String variables, compares them, extracts characters, converts case, concatenates, and searches for indexes. The output verifies the results of applying each method to the sample strings.

Uploaded by

avishana
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)
40 views1 page

A Val Val1 Val3 Val2 Val Val1 Val Val2 Val Val2 Val Val Val3 Val Val Val Val Val1 Val Val Val Val Val Val

This Java code demonstrates various string methods in Java including ==, equals(), length(), charAt(), toLowerCase(), concat(), replace(), substring(), indexOf(), and lastIndexOf(). It creates String variables, compares them, extracts characters, converts case, concatenates, and searches for indexes. The output verifies the results of applying each method to the sample strings.

Uploaded by

avishana
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/ 1

public class Str4 {

public static void main(String a[])


{
String val="java programming";
String val1="java programming";
String val3="JAVA PROGRAMMING";
String val2=new String("java programming");
System.out.println("== method string literal"+":"+(val==val1));
System.out.println("== method new and string literal"+":"+(val==val2));
System.out.println("equals method"+":"+(val.equals(val2)));
System.out.println("length is"+val.length());
System.out.println("equals Ignore case"+":"+val.equalsIgnoreCase(val3));
System.out.println("Character at"+":"+val.charAt(0));
System.out.println("LowerCase function"+":"+val.toLowerCase());
System.out.println("Uppercase function"+":"+val.toUpperCase());
System.out.println("concatenation"+":"+val.concat(val1));
System.out.println("replace"+val.replace('j', 'v'));
System.out.println(val);
System.out.println("substring(one par)"+val.substring(2));
//System.out.println("substring(two par)"+val.substring(3,7));
System.out.println("index of"+val.indexOf('a'));
System.out.println("last index of"+val.lastIndexOf('a'));
System.out.println("last index of(two param)"+val.lastIndexOf('p', 30));

o/p:

== method string literal:true


== method new and string literal:false
equals method:true
length is16
equals Ignore case:true
Character at:j
LowerCase function:java programming
Uppercase function:JAVA PROGRAMMING
concatenation:java programmingjava programming
replacevava programming
java programming
substring(one par)va programming
index of1
last index of10
last index of(two param)5

You might also like