Turn Desktop View Off
by Dinesh Thakur

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.

import java.io.*;

class SplitFunction
       public static void main(String args[]) throws IOException
             BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
             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