I have a String s="abc" in Java. What is s[0] type? Isn’t it a String type?
I try to print it in Java, but it shows "The type of the expression must be an array type but it resolved to String";
>Solution :
The square brackets are used to access the elements in an Array type.
String is an object, and so you can’t access it’s characters via [].
To access individual characters, you could either:
- s.charAt(index)
- char[] charArr = s.toCharArray(); and access charArr[idx]