Java - Write code to get Splitted String by index

Requirements

Write code to get Split String

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        String regex = "o";
        int index = 2;
        System.out.println(getSplitString(str, regex, index));
    }// w ww.  j a va  2 s . com

    public static String getSplitString(String str, String regex, int index) {
        String[] str_array = str.split(regex);
        return str_array[index];
    }
}

Related Exercise