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));
    }//from   w  w w .j  a  va  2  s  .c o  m

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

Related Exercise