Java - Write code to get Splitted String by index


Write code to get Split String


//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "";
        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