Examveda
Examveda

What is the output of the following println statement?
String str1 = "Hellow";
System.out.println(str1.indexOf('t'));

A. true

B. false

C. 1

D. -1

E. 0

Answer: Option D


This Question Belongs to Java Program >> Strings

Join The Discussion

Comments ( 5 )

  1. Himanshu Singh
    Himanshu Singh :
    2 years ago

    indeof returns -1 if char is not availabele

  2. Mounika Gutha
    Mounika Gutha :
    5 years ago

    indexOf() returns the value of index if it is present .Otherwise it returns -1;

  3. Dileep Tiwari
    Dileep Tiwari :
    6 years ago

    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

  4. Pushpa Latha
    Pushpa Latha :
    7 years ago

    as we cannot find the letter in the string indexOf returns -1

  5. Avinash Singh
    Avinash Singh :
    8 years ago

    Here compilation error because String s1 = 'SITHA' ;
    String s2 = 'RAMA'; . if String than output will be true.

Related Questions on Strings