How to Sort Strings which are given in List and display in
ascending order without using java api.



How to Sort Strings which are given in List and display in ascending order without using java api...

Answer / kumar

public class sorting_strings
{
static void sortString()
{
String a[]={"n","g","a","i","h","v","q"};

for (int i = 0; i < a.length; i++)
{
for (int j = 0; j < a.length; j++) {
int num=a[i].compareTo(a[j]);
//System.out.println("num="+num);
if(num>=0)
{
String temp=a[i];
a[i]=a[j];
a[j]=temp;

}

if(num<0)
{
//String temp=a[i];
a[i]=a[i];
a[j]=a[j];

}
}
}
//display
int x=a.length;
for (int i =(x-1); i>=0 ; i--) {
System.out.print(a[i]+" ");
}
}
public static void main(String[] args) {

sortString();
}

}

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Core Java Interview Questions

Is set thread safe java?

0 Answers  


How to use scanner in java?

1 Answers  


what is a static block?

4 Answers  


what is the purpose of class "Object" which is base class for all classes?

3 Answers  


What is the size of boolean variable?

0 Answers  






I want to store more than 10 objects in a remote server? Which methodology will follow?

0 Answers  


Can we use synchronized block for primitives?

0 Answers  


What is the purpose of void class?

0 Answers  


what are depricated methods ?

5 Answers   Satyam,


What is a nested list?

0 Answers  


What is the difference between choice and list?

0 Answers  


What is java english?

0 Answers  


Categories