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));
    }/*  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