Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) {
        String pattern = "[,\\s]+";
        String colours = "Red,White, Blue   Green        Yellow, Orange";

        Pattern splitter = Pattern.compile(pattern);
        String[] result = splitter.split(colours);

        for (String colour : result) {
            System.out.println("Colour = \"" + colour + "\"");
        }
    }
}