• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hi output in s.indexOf() is getting -1 why is that so?  RSS feed

 
Vishal Hegde
Ranch Hand
Posts: 1078
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class bucky3
{
public static void main(String args[])
{
String s="VishalJaganmohanHegde";

System.out.println(s.indexOf('k',5));
}
}
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because there is no 'k' in the string "VishalJaganmohanHegde".

The API documentation of String.indexOf() says:
Returns: the index of the first occurrence of the character in the character sequence represented by this object, or -1 if the character does not occur.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!