Java - Write code to get Before Separator Or All

Requirements

Write code to get Before Separator Or All

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String name = "book2s.com";
        System.out.println(getBeforeSeparatorOrAll(name));
    }/*from   w w w .  j ava2s  .c  o  m*/

    private static final String SEPARATOR = ":";

    public static String getBeforeSeparatorOrAll(String name) {
        int index = name.indexOf(SEPARATOR);
        if (index == -1)
            return name;
        return name.substring(0, index);
    }
}

Related Exercise