Java String indexof

https:/‮ual.www/‬tturi.com
Java String indexof

The java string indexOf() method returns index of given character value or substring. If it is not found, it returns -1. The index counter starts from zero.

/**
 * @author lautturi.com 
 * Java example: Java String indexof method - Returns the index within this string of the first occurrence of the specified substring. 
 */

import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		String text = "HelloJava World";
		int firstLletterPosition = text.indexOf('l');
		
		int subStrPosition = text.indexOf("Wo");
		
		System.out.println(firstLletterPosition);
		System.out.println(subStrPosition);
	}
}
Created Time:2017-09-25 02:02:48  Author:lautturi