Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.text.BreakIterator;
import java.util.Locale;

public class Main {
    public static void main(String[] args) {
        String text = "this is a test(this is a test).";
        BreakIterator wordIterator = BreakIterator.getWordInstance(Locale.getDefault());
        extractWords(text, wordIterator);
    }

    static void extractWords(String target, BreakIterator wordIterator) {
        wordIterator.setText(target);
        int start = wordIterator.first();
        int end = wordIterator.next();

        while (end != BreakIterator.DONE) {
            String word = target.substring(start, end);
            if (Character.isLetterOrDigit(word.charAt(0))) {
                System.out.println(word);
            }
            start = end;
            end = wordIterator.next();
        }
    }
}