• Post Reply Bookmark Topic Watch Topic
  • New Topic

IndexOf(help needed)  RSS feed

 
albert lekaj
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell me how to use the IndexOf method and it's syntax, I will be very thankfull
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Albert. Welcome to The Ranch!

Which indexOf method do you mean? (and note the capitalisation - it matters). All methods belong to a class, and I can think of several classes that have an indexOf method (and, of course, anyone can write their own class that does). For starters, both java.lang.String and java.util.List have one. The Javadocs for the relevant class should tell you how to use it, as long as you know how to call methods in the first place.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
albert lekaj wrote:Can anyone tell me how to use the IndexOf method and it's syntax, I will be very thankfull

int x = "Hello".indexOf('l');
System.out.println(x);

will display
2

That covers what you should need for String.indexOf() (at least indexOf(int); there are 3 other signatures); but, as Matthew said, other classes also have indexOf() methods.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!