Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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 difference Between Core Java and advance java

60 Answers   HCL, HP, Sambalpur University, TCS, Vensai Technologies, Wipro,


What is the purpose of void?

0 Answers  


What is the difference between Array and Hash Table?

0 Answers   Impetus,


What is the difference between C++ & Java?

78 Answers   College School Exams Tests, HAL, SUN, Syntel, TCS, Wipro,


what is meant by abstract class?

0 Answers   Aspire,


What is parseint?

0 Answers  


Can we start a thread twice in java?

0 Answers  


What is the GregorianCalendar class?

2 Answers   HCL,


How to declare an arraylist in java?

0 Answers  


What will be the default values of all the elements of an array defined as an instance variable?

0 Answers  


when should you use stringbuilder class in a program?

0 Answers  


what is template design pattern?

0 Answers  


Categories