import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/*
* 字符串反转,两种方法
*/
public class ReverseString {
//方法一
public String[] reverse(String str){
String[] opsite=str.split(" ");
int size=opsite.length;
String []t=new String[size];
for(int i=0;i<size;i++){
t[i]=opsite[size-i-1];
System.out.print(t[i]+ " ");
}
return t;
}
//方法二
public void reverse2(String str){
String[] opsite=str.split(" ");
List<String> list = new ArrayList<String>();
list = Arrays.asList(opsite);
Collections.reverse(list);
for(String word:list){
System.out.print(word+" ");
}
}
/**
* @param 字符串反转
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String str="I LOVE JAVA";
ReverseString r=new ReverseString();
r.reverse2(str);
}
}