Results 1 to 2 of 2
Thread: Sorting string Array Values
- 01-14-2011, 06:53 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Sorting string Array Values
I am having a problem on how I couldn't sort my array values. My codes don't work the way I wanted them to:
int n;
JTextArea outputArea= new JTextArea();
String class1[]= new String [8];
JOptionPane.showMessageDialog(null,"Enter 8 Students for Class 1 ");
n=1;
for (int i=0; i<class1.length; i++){
String input=
JOptionPane.showInputDialog("Student # : "+n);
class1[i]=input;
n++;
}
String output= "\n\t Class1 Students\n";
for(int i=0; i<class1.length; i++)
output+="\t "+class1[i]+"\t"+"\t\n";
outputArea.setText(output);
JOptionPane.showMessageDialog(null, outputArea, "Initializing an Array of int Values", JOptionPane.PLAIN_MESSAGE);
for (int indx=0; indx<class1.length; indx--){
int high=1;
for(int i=2; i<= indx; i++){
if (class1[i]>class1[high]){
high=2;
}
if (high!=indx){
int temp= class1[high];
class1[high]=class1[indx];
class1[indx]=temp;
}
}
- 01-14-2011, 07:08 AM #2
Do you really mean to decrement it? indx-- ?
If you want to sort String values, you can store them inside ArrayList and sort by using the Collections.sort(List<T> list).
See if you can go for that approach.
GoldestJava Is A Funny Language... Really!.gif)
Click on * and add to member reputation, if you find their advices/solutions effective.
Similar Threads
-
Sorting Array
By saqib15 in forum New To JavaReplies: 1Last Post: 02-12-2010, 03:42 AM -
Having trouble insert/sorting array values w/ binary searching.
By bh-chobo in forum New To JavaReplies: 2Last Post: 10-07-2009, 06:24 PM -
Sorting JTable on more than just the values listed in the columns
By Jeegen in forum AWT / SwingReplies: 7Last Post: 09-23-2009, 07:28 PM -
sorting variable values in ascending order?
By jeffrey in forum New To JavaReplies: 0Last Post: 07-14-2009, 07:59 AM -
Sorting an array of Strings
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:39 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks