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

What is contractor means and methods?

0 Answers  


How to split a string in java?

0 Answers  


What is difference between hashset and hashmap?

0 Answers  


what is meant by abstract class?

0 Answers   Aspire,


Can we convert integer to string in java?

0 Answers  






What are runtime exceptions?

0 Answers  


What is the difference between numeric and integer?

0 Answers  


where u use Abstraction and Interface in real time

3 Answers   Sonata,


What does a method signature consist of?

0 Answers  


What is keyset in java?

0 Answers  


what is mena by object block any what is the use of that

0 Answers   CGI,


What an i/o filter?

0 Answers  


Categories