/**
* @author lautturi.com
* Java example: Testing if a string is found or not
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
byte[] arr = { 'h', 'e', 'l', 'l', 'o', ' ', 'l', 'a', 'u', 't', 't', 'u', 'r', 'i', '.', 'c', 'o', 'm', 'j',
'a', 'v', 'a' };
String text = new String(arr);
String findme = "java";
int pos = text.indexOf(findme);
if (pos >= 0)
System.out.println("Found the first " + findme + " at the position:" + pos);
else
System.out.println("Not found ");
}
}
output:
Found the first java at the position18