Back to Browse

Predefined Methods in String

1.7K views
Streamed live on May 24, 2021
36:12

Java Strings Predefined Methods =============== String:- String is Group of characters number :- single digit ,combination of digits String in java is a predefined class which provides readymade methods to perform operations on group of characters 1. length() :- This method is used to count the no of characters that are available in the given string String x="kannababu"; System.out.println(x.length()); Ex:- class StrDemo { public static void main(String[] args) { String x="kannababu"; System.out.println(x.length()); } } 2.String toLowerCase() :- This method is used to convert uppercase string into lowercase string class StrDemo { public static void main(String[] args) { String x="KANNABABU"; System.out.println(x.toLowerCase()); } } 3. String toUpperCase():- This method is used to convert lower string into uppercase string class StrDemo { public static void main(String[] args) { String x="kannababu"; System.out.println(x.toUpperCase()); } } 4. String concat(String str):- class StrDemo { public static void main(String[] args) { String x="kannababu"; System.out.println(x.concat("is a trainer")); } } 5. String substring(int beginindex):- This method is used to return the substring from the given string class StrDemo { public static void main(String[] args) { String x="kannababutrainer"; System.out.println(x.substring(5)); } } String substring(int beginindex,int endindex):- This method is used to return the substring from the given string class StrDemo { public static void main(String[] args) { String x="kannababutrainer"; System.out.println(x.substring(5,9)); } } 6. charAt():- This method returns the character at a specific position String str="welcome"; char ch=str.charAt(0); System.out.println(ch); 7. compareTo():-This method is used to compare 2 strings class StrDemo { public static void main(String[] args) { String str1="welcome"; String str2="welcome"; System.out.println(str1.compareTo(str2)); } } 8. replace():- replace a specific in the given string class StrDemo { public static void main(String[] args) { String s="there,is,a,cat"; System.out.println(s.replace(',',' ')); } } Q) String s="sat56h72a"; wap to find the sum of the digits in the given string? a-z 65-90 A-Z 97-122 0-9 48-57

Download

1 formats

Video Formats

360pmp446.2 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Predefined Methods in String | NatokHD