I need to convert a StringBuffer Array to String Array for sorting. Is there any method in Java?
Below is my code and i am trying to sort the values(input1) in alphabetical order that contains the first letter as UpperCase and ignoring other values.
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}");
}
}
StringBuffer
at all. You just want to sort a string array according to the first uppercase char in those strings! Do you want your output as{"One", "Three", "foUr"}
? – Marko Topolnik May 11 '12 at 14:23