Call string class methods using string literals

Yes, we can call string class methods using string literals.

Example

package com.w3spoint;
 
public class Test {
	public static void main(String args[]){
		System.out.println("w3spoint".charAt(3));
		System.out.println("w3spoint".indexOf('i'));
	}
}

Output

p
5

Java interview questions on String Handling

Content Protection by DMCA.com
Please Share