我需要将 StringBuffer Array 转换为 String Array 进行排序。Java中有什么方法吗?
下面是我的代码,我试图按字母顺序对值(input1)进行排序,其中包含作为大写的第一个字母并忽略其他值。
import java.util.*;
public class IPLMatch
{
public static void main(String args[])
{
int input1 = 4;
String input2[] = {"One","two","Three","foUr"}, output[];
StringBuffer[] temp = new StringBuffer[input1];
int j = 0, k = 0;
for(int i = 0; i < input1; i++)
{
boolean isUpperCase = Character.isUpperCase(input2[i].charAt(0));
if(isUpperCase)
{
temp[j++] = new StringBuffer(input2[i]);
}
}
//I need convert my stringbuffer array (temp) to String array for sorting
Arrays.sort(temp);
System.out.print("{");
for(int i = 0; i < temp.length; i++)
{
System.out.print( temp[i]+ ",");
}
System.out.print("\b}");
}
}