class Sample { public static void main(String[] args) { String str = "cyberee Success"; // charAt() method is starting from zero and it will return charectar specified in this index. System.out.println(str.charAt(2)); System.out.println(str.charAt(4)); //The indxOf method will acept one of the argument charectar and it will return the index of the chaectar. System.out.println(str.indexOf("b")); System.out.println(str.indexOf("z")); // In lastIndexOf() :- the last index print the last occerence of the spicified charectarwih the string. System.out.println(str.lastIndexOf("e")); System.out.println(str.lastIndexOf("s")); // If it not present then it will prent the value -1 System.out.println(str.lastIndexOf("z")); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter