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));
    }/*  ww  w.  j  a v  a  2  s.c  om*/

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

Related Exercise