answersLogoWhite

0

indexOf is a method of the String class. Since the indexOf method is overloaded, I will be using the indexOf(String str) version in this example. According to the API Documentation, this method "Returns the index within this string of the first occurrence of the specified substring." So, if you wanted to find the position of the letter 'v' in the String 'Java' and print it out, you would do this: String str = "Java"; int i = str.indexOf("v");

System.out.println(i);

If the character you passed in the indexOf method does not exist in the String, indexOf would return a -1 (negative one).

User Avatar

Wiki User

15y ago

What else can I help you with?