Methods in string classes

PHOTO EMBED

Tue Apr 25 2023 17:33:36 GMT+0000 (Coordinated Universal Time)

Saved by @Shankar #instanceblocks #inheritance #overloading

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"));
	}
}
content_copyCOPY