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 return keyword in java?

0 Answers  


Explain yield() method in thread class ?

0 Answers  


diffrence b\w println() and printf()

8 Answers   NIIT,


Is it possible to specify multiple jndi names when deploying an ejb?

0 Answers  


What is not object oriented programming?

0 Answers  






what do you mean by classloader in java?

0 Answers  


My application URL : http://localhost:8080/Application/Login.jsp. When a user enter this url in IE then, how it get Login.JSP Page exactly? what are the processes will happen from when we submit the URL to get Login.jsp?

3 Answers   IBM, TCS,


What is basic concept of static in java ?

1 Answers   iGate,


How many JVMs can run on a single machine and what is the Just-In-Time(JIT) compiler?

0 Answers   Global Logic,


Explain restrictions on using enum?

0 Answers  


What are data structures in java?

0 Answers  


if a java file without any source code is valid java file?

3 Answers   SparkTG,


Categories