0% found this document useful (0 votes)
14 views7 pages

Day3 String

Uploaded by

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

Day3 String

Uploaded by

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

Java

WWW.PAVANONLINETRAININGS.COM
Strings
▪ length(): It returns count of total number of characters present in the String.

String s=“Welcome” s.length() 7

▪ concat() : Combines a specific string at the end of another string and ultimately returns a combined
string. It is like appending another string.

String s=“Welcome”
s.concat(s1) Welcome To Java
String s1=“ To Java”

▪ trim() : The java string trim() method removes the leading and trailing spaces.

String s=“ Welcome ” s.trim() Welcome

WWW.PAVANONLINETRAININGS.COM
Strings
▪ charAt(): Returns a char value at the given index number. The index number starts from 0.

String s=“Welcome” s.charAt(3) c

▪ contains() : Searches the sequence of characters in this string. It returns true if sequence of char values are found
in this string otherwise returns false.

String s= “Welcome” s.contains(“Wel”) True

▪ equals() : Compares the two given strings based on the content of the string. If any character is not matched, it
returns false. If all characters are matched, it returns true.

String s=“Welcome” s.equals(“Welcome”) True

String s=“Welcome” s.equals(“welcome”) False

WWW.PAVANONLINETRAININGS.COM
Strings

▪ equalsIgnoreCase() : Compares two string on the basis of content but it does not check the case like
equals() method. In this method, if the characters match, it returns true else false.

String s=“Welcome” s.equalsIgnoreCase(“Welcome”) True

String s=“Welcome” s.equalsIgnoreCase(“welcome”) True

▪ replace(): Returns a string, replacing all the old characters or CharSequence to new characters. There
are 2 ways to replace methods.

String s=“Welcome” s.replace(’e’, ’a’) Walcoma


String s=“Welcome To Java” s.replace(“Java”, ”Selenium”) Welcome To Selenium

WWW.PAVANONLINETRAININGS.COM
StringsStrings
▪ Substring() : Returns substring of a string based on starting index and ending index.

Starting Index 0 1 2 3 4 5 6
s W E L C O M E
Ending Index
1 2 3 4 5 6 7

String s=“Welcome” s.substring(1,3) el

String s=“Welcome” s.substring(0,4) Welc

String s=“Welcome” s.substring(2,4) lc

WWW.PAVANONLINETRAININGS.COM
StringsStrings
▪ toLowerCase(): returns the string in lowercase letter.

String s=“WELCOME” s.toLowerCase() welcome

▪ toUpperCase(): returns the string in Uppercase letter.

String s=“welcome” s.toUpperCase() WELCOME

WWW.PAVANONLINETRAININGS.COM
Assignment (Strings)

1. Write a java program to compare two strings, ignoring case differences.


2. Write a Java program to concatenate a given string to the end of another string.
3. Write a java program to get the length of a given string
4. Write a Java program to get a substring of a given string between two specified positions
5. Write a Java program to convert all the characters in a string to uppercase.
6. Write a Java program to convert all the characters in a string to lowercase.
7. Write a Java program to reverse a string.
8. Write a Java program to count number of time a character repeated in a string.
9. Write a Java program to convert integer to string.
10.Write a Java program to convert string to integer.
11.Write a Java program to Swap the 2 strings.
12.Write a program to check a string is palindrome or not

WWW.PAVANONLINETRAININGS.COM

You might also like