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 the four pillars of java?

0 Answers  


How do you check if a character in a string is a digit or letter?

0 Answers  


How much is a java license?

0 Answers  


What is the benefit of abstract class?

0 Answers  


How does linkedlist work in java?

0 Answers  






What are heap memory and stack memory and what are memory tables.

0 Answers   Aspiring Minds,


How does thread synchronization occurs inside a monitor?

0 Answers  


Describe what happens when an object is created in java ?

0 Answers  


How many bits are allocated to represent character of character sets - Unicode, ASCII, UTF-16, UTF-8?

1 Answers  


Can anonymous class have constructor?

0 Answers  


Why we need Finally with try? pls expain with ur example..

3 Answers   BitWise, HDFC, TCS,


why java main method is given as static method?

2 Answers  


Categories