1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
package string_manipulation; public class StringMethods { public static void main(String[] args) { String s=" hello Friends "; String s2 = s.concat("my name is abc"); System.out.println(s); s=s.concat("my name is abc"); System.out.println(s); //equals method check the content of string so it will return boolean value if(s.equals(s2)) { System.out.println("both are same"); } else{ System.out.println("different in equals"); } //It will check address of giver reference variable &return boolean value if(s==s2){ System.out.println("Pointing to same address"); } else{ System.out.println("pointing to different address"); } //It will give the length of string System.out.println(s.length()); //It will return the character of 4th index System.out.println(s.charAt(4)); //To remove whitespaces from starting and ending of perticular string System.out.println(s.trim()); //to check string is empty or not it will return boolean value System.out.println(s.isEmpty()); // It will replace character 'e' with 's' System.out.println(s.replace("e", "S")); //return the address of the string object System.out.println(s.hashCode()); //Convert the given string into upperCase System.out.println(s.toUpperCase()); // split() will convert string into string array String[] a = s.split(""); } } |
Need answers for these problems, create separate post for these problems:
How to find the maximum occurring character in given String?
How to remove all duplicates from a given string?
How to print the duplicate characters from the given String?
How to remove characters from the first String which are present in the second String?
How to check if two strings are rotations of each other?
How to reverse a given String?
How to print all permutation of a String?
How to reverse the words in a given String sentence?
How do you check if a given String is Palindrome or not?
How do you convert String to integer?
How do you remove a given character from String?
How do you count a number of words in String?
How to return highest occurred character in a String?
How to return highest occurred character in a String?
How to return highest occurred character in a String?
How to return highest occurred character in a String?
Add code for some real time interview questions like how to get number of Captial A in the string, “I Am Awesome”. Write code to make use of these methods, mere knowning these methods is not enough, you need to learn to make use of it in real logical problems. Add solutions to top 5 string manipulation questions here.