import java.lang.*;
import java.util.*;
public class arraySort{
public static void main(String[] args)
throws java.io.IOException{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String names[] = new String[10];
int i = 0;
for(i = 0; i < 10; i++){
System.out.print("Enter a name: ");
names[i] = br.readLine();
}
/************************************************/
/*Here is where I want to sort them in alphabetical order. */
/************************************************/
for(i = 0; i < 10; i++)
System.out.println(names[i]);
}
}
Some array sortingNot exactly sure how to implement this.
Page 1 of 1
4 Replies - 4345 Views - Last Post: 06 April 2007 - 02:14 AM
#1
Some array sorting
Posted 02 April 2007 - 06:51 PM
So I've been searching the api and trying who knows how many different ways to do this, but I can't get an array of strings to sort in alphabetical order. There's more to this whole program, but just to get the idea down:
Replies To: Some array sorting
#2
Re: Some array sorting
Posted 02 April 2007 - 06:55 PM
I might be tempted to implement it as an Array object, and use the sort() method.
http://java.sun.com/...til/Arrays.html
http://leepoint.net/.../70sorting.html
http://www.java2s.co...ayofStrings.htm
http://java.sun.com/...til/Arrays.html
http://leepoint.net/.../70sorting.html
http://www.java2s.co...ayofStrings.htm
#3
Re: Some array sorting
Posted 02 April 2007 - 07:21 PM
You can have a String array, and use the Arrays.sort(Object[] a) method. It sorts based on natural value, which for Strings is the lexical, or alphabetical order.
#4
Re: Some array sorting
Posted 05 April 2007 - 07:26 PM
Why dont you give buble sort a try in your code or some other algoritm
#5
Re: Some array sorting
Posted 06 April 2007 - 02:14 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|