Recently found such a topic, how to use the string recursive way output:
As the string "Hello World my friend and now"--〉now and friend my world Hello
To achieve this method a lot, my method may be inefficient, if there is a better way please advise.
public static void Main (string[] args) {System.out.println (Reserve (""));} public static string reserve (String str) {string objstr= ' Hello world my friend and now '; object[] Array=objstr.split (""); Ob Ject[] Nowarry=str.split (""); Array=compare (array, nowarry); if (array.length<1) {return str;} for (int i=array.length-1;i>=0;i--) {str=str+ "" "+array[i];reserve (str);} return str;} private static object[] Compare (object[] array,object[] nowarry) {list<object> endlist=new arraylist<object > (); List<object> ownlist=new arraylist<object> (); for (int. i=0;i<array.length;i++) {for (int j=0;j< nowarry.length;j++) {if (Array[i].equals (Nowarry[j])) {Ownlist.add (array[i]);}} Endlist.add (Array[i]);} Endlist.removeall (ownlist); return Endlist.toarray ();}
[Result show]: now and friend my world Hello
It is important to note that the classcastexception exception occurs when the Endlist.toarray () conversion is performed in the system when string[is used to identify the array. So replace all of the above strings with object objects.
If there is a simpler way to implement, please advise. Thank you
Java output A string in reverse order recursively