How to Sort list of Strings in ascending order without using
java api.



How to Sort list of Strings in ascending order without using java api...

Answer / megha

package practise;

import java.util.Scanner;

class Sorting {
public static void main(String[] input)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the count :\t ");
int k=sc.nextInt();
String temp=new String();
String names[]=new String[k];
System.out.println("enter the names");
for(int i=0;i<k;i++)
{
names[i] = sc.next();
}
for( int i=0;i<k;i++)
{
for(int j =i+1;j<k;j++)
{
if(names[i].compareTo(names[j])>0)
{
temp = names[i];
names[i] = names[j];
names[j] = temp;
}
}
}
for(String name:names)
{
System.out.println(name);
}
}
}

Is This Answer Correct ?    25 Yes 0 No

Post New Answer

More Core Java Interview Questions

What are virtual functions?

2 Answers  


Why bytecode is called bytecode?

0 Answers  


string is immutable? right every one knows that, my question is it advantage or disadvantage making string immutable?

5 Answers   HCL,


What is low level language in computer?

1 Answers  


Explain about the select method with an example?

0 Answers  






What is an Applet ?

2 Answers  


How are the elements of a gridbaglayout organized?

0 Answers  


What does flagged out mean?

0 Answers  


Does isempty check for null?

0 Answers  


What releases of Java technology are currently available? What do they contain?

1 Answers  


In what type of containers, Border layout is a default layout?

3 Answers  


How do you convert boolean to boolean?

0 Answers  


Categories