key word
  • str.indexOf(str_space, n4 + 1);

import java.io.*;
import java.lang.String.*;
import java.lang.*;
//javac string_indexof_b.java
class string_indexof_b{
public static void main(String arguments[])throws IOException

{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
//needs throws IOException
System.out.print("Type some thing : ");
String str =br.readLine();
//get the length of the string
//note length()
int str_length = str.length();
System.out.println (" string length " + str_length);
String str_space = " ";
int n1 = str_space.length();
int n4 = str.indexOf(str_space);
//System.out.println ("No of str_space are : " + n1 + " string length " + n4);
while(n4>0)
{
System.out.println("--while loop finds space at : " + n4 );
n4 = str.indexOf(str_space, n4 + 1);
}
////
System.out.println("--str.split will brak the sentence at str_space--");
System.out.println("--c_space = words[i].toCharArray() displays words;--");
String[] words = str.split (" ");
int m1 = words.length;
int m4 = str.indexOf("");
System.out.println ("No of words are : " +m1);
char[] c_space = new char[m1];
for (int i =0; i <= m1-1; i++)
{
c_space = words[i].toCharArray();
System.out.println(c_space);
System.out.println ("\t round " + i + " " + words[i]);
System.out.println ("\t indexof " + i + " " + words[m4]);
}//end for loop
}
}
/*
Note:
String[] words = str.split (" ");
int n1 = words.length;
int n4 = str.indexOf("");
System.out.println ("No of words are : " +n1);
char[] c_space = new char[n1];
for (int i =0; i <= n1-1; i++)
{
c_space = words[i].toCharArray();
System.out.println(c_space);
System.out.println ("\t round " + i + " " + words[i]);
System.out.println ("\t indexof " + i + " " + words[n4]);
}//end for loop
*/