Thursday, 22 January 2015

Program to split a String without using split() method



Program to split a String without using split() method import java.util.*;
public class SplitString
{
public static void main(String[] args) {
   String[] s = {"Netherlands_Iceland_Norway_Denmark"};
   String[] finalString = mymethod(s);      
   for (int i = 0; i < s.length; i++) {
       System.out.println("" + finalString[i]);
   }
}

static public String[] mymethod(String[] mystring) {
   String ss[] = new String[mystring.length];
   for (int j = 0; j < mystring.length; j++) {
       ss[j] = mystring[j].replace('_', ' ');
   }
   return ss;
}
}

No comments:

Post a Comment