Wednesday, 11 January 2017

Different String operations

public class String1 {
public static void main(String[] args) {
String s =”rakesh”;
System.out.println(s.charAt(3)); // to print the char at given position
System.out.println(s.codePointAt(1)); // to print the ascii value of given position character
System.out.println(s.codePointBefore(1)); // it prints the ascii value of the index given to its before index
System.out.println(s.codePointCount(1, 4)); // find the range between endindex-beginindex
System.out.println(s.compareTo(“Rakesh”)); // if string is same it represents 0 else something else but it checks case
System.out.println(s.compareToIgnoreCase(“Rakesh”)); // it ignores case and gives input as 0 here
System.out.println(s.concat(” prasad”)); // used to concat two string
System.out.println(s.contains(“ra”)); // used to search specified value in string or not
System.out.println(s.contentEquals(“rakeshh”)); // used to check both the strings are same or not
System.out.println(s.endsWith(“keshh”)); // used to check whether the string ends with given suffix
System.out.println(s.equals(“pramod”)); // checks whether one string is equal to another or not
System.out.println(s.hashCode()); // returns the hashcode of a string
System.out.println(s.indexOf(3));
System.out.println(s.indexOf(“rak”));
System.out.println(s.isEmpty());
System.out.println(s.lastIndexOf(“k”));
System.out.println(s.substring(2));
System.out.println(s.split(” “));
}
}
Output :-
e
97
114
3
32
0
rakesh prasad
true
false
false
false
-938374178
-1
0
false
2
kesh
[Ljava.lang.String;@15db9742

No comments:

Post a Comment