What is the output of the following println statement?
String str1 = "Hellow";
System.out.println(str1.indexOf('t'));
String str1 = "Hellow";
System.out.println(str1.indexOf('t'));
A. true
B. false
C. 1
D. -1
E. 0
Answer: Option D
Join The Discussion
Comments ( 5 )
Related Questions on Strings
In Java, which class is used to represent a sequence of characters as a string?
A. String
B. StringBuilder
C. StringSequence
D. StringArray
What is the correct way to create a new empty String object in Java?
A. String emptyString = "";
B. String emptyString = new String();
C. String emptyString = " ";
D. String emptyString = null;
E. Both A and B
Which of the following methods is used to compare two strings for equality in Java?
A. equals()
B. compareTo()
C. equalsIgnoreCase()
D. compare()
indeof returns -1 if char is not availabele
indexOf() returns the value of index if it is present .Otherwise it returns -1;
I would like to request to Examveda please make option of upvote and downvote of answer Otherwise its really hard to understand whose opinion is right. Thanks
as we cannot find the letter in the string indexOf returns -1
Here compilation error because String s1 = 'SITHA' ;
String s2 = 'RAMA'; . if String than output will be true.