This program is mainly used for revere the given String Words using String Tokenizer 's.

ProgramHow To Reverse a Given String in Java.


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import sun.util.locale.StringTokenIterator;

public class ReverseString {

    public static void main(String[] args) {

        String input=" hai macha";

        StringTokenIterator iterator=new StringTokenIterator(input, " ");

        List<String> data=new ArrayList<String>();

        while(iterator.hasNext())
        {
            data.add(iterator.next()+" ");
        }

        Collections.reverse(data);

        for(String output:data) System.out.print(output);

          System.out.println("");
                          
    }
   
}

OutPut:

macha hai

0 comments:

Post a Comment