Splitting a string into matches and their offsets in java

www‮ruttual.‬i.com
Splitting a string into matches and their offsets in java
/**
 * @author lautturi.com
 * Java example:  split string into matches and their offsets in java
 */

import java.util.*;

public class Lautturi {

	public static void main(String[] args) {

		String str = "hello lautturi java world";
		
		String[] matches = str.split(" "); 
  
		System.out.println(Arrays.toString(matches)); 
		
		System.out.println(matches[0]); 
		
        for (int i=0;i<matches.length;i++)
            System.out.println(matches[i]); 
		
	}
}

output:

[hello, lautturi, java, world]
hello
hello
lautturi
java
world
Created Time:2017-09-16 14:23:48  Author:lautturi