by Dinesh Thakur Category: Stream

In Split Function Java Example, the string t is split into pieces (wherever space has occurred in it) with the help of split() method and all its pieces are then stored in the string array h. Then, the length of the string h is computed by length() function and the loop is invoked in reverse to display the tokens stored in string array h in reverse order.


class SplitFunction
       public static void main(String args[]) throws IOException
             BufferedReader bf=new BufferedReader(new InputStreamReader(;
             String t;
             int i,n;
             System.out.println("Enter a line of text");
             String[] h = t.split(" ");
             System.out.println("the words in reverse order are");

Split Function in Java with Example

Popular Article