How to Sort Strings which are given in List and display in
ascending order without using java api.
Answer Posted / 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 View All Answers
Why are there no global variables in java?
Can we create constructor in abstract class ?
Explain garbage collection in java?
What is a protected class in java?
What is the difference between equals() and?
In Java list the methods that can be overridden?
What are "methods" and "fields"?
What is the impact of declaring a method as final?
How do you use wildcards?
What is meant by design patterns?
What is the functionality of the stub?
How do you convert an int to a string in java?
What is the difference between heap memory and stack memory?
What is private static class in java?
What are parsing rules?