- method is used to exhibits functionality of an object.
- method is invoke explicitly
- method may/may not return value
- in the case of method no default method is provided.
- method should not having name as that class
import java.io.*;
import java.util.*;
class test
{
public static void main(String[] args)
{
String s="GeeksforGeeks";
System.out.println("String length: "+s.length());
System.out.println("Character at 3rd
position:"+s.charAt(3));
System.out.println("Substring:"+s.substring(3));
System.out.println("Substring2:"+s.substring(2,5));
String s1="Geeks";
String s2="forGeeks";
System.out.println("concatenated string:"+s1.concat(s2)); String s4="Learn Share Learn"; System.out.println("Index of
share:"+s4.indexOf("Share"));
System.out.println("Index of a:"+s4.indexOf('a',3));
Boolean out="Geeks".equals("geeks");
System.out.println("checking equality:"+out);
out="Geeks".equals("Geeks");
System.out.println("checking equality:"+out);
int out1=s1.compareTo(s2); System.out.println("If s1=s2:"+out1); String word1="GeekyMe"; System.out.println("changing to lower
case:"+word1.toLowerCase());
String word2="GeekyME"; System.out.println("changing to upper
case:"+word2.toUpperCase());
String word4="Learn Share Learn"; System.out.println("Trim the word:"+word4.trim()); String str1="feeksforfeeks"; System.out.println("original String:"+str1);
String str2="feeksforfeeks".replace('f','g'); System.out.println("Replaced f with g:"+str2);
}
}
Output :-
0 Comments