File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes sorting an array from csv file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sorting an array from csv file." Watch "sorting an array from csv file." New topic
Author

sorting an array from csv file.

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 102
I have a csv file that i'm reading in and I have got all the items in the file to get stored in a variable and the commas have been taken out with parsing. Each line in the csv file is a new person with personal attributes such as favorite pet. I would Like to sort this array of people by which pet is their favorite. I want all the people who like cats to be sorted out from the ones who like other animals and then alphabetized. I was thinking I could iterate through each line of persons and find their favorite pets in [X] part of the array but how do I take the complete line of the persons name who likes cats and attributes and store it in a new sorted array? Do I do something like this:

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
How do I get the value of the third item in the array into a variable to test it against cat?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Why are you using == on Strings?
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
Yeah I figured that wouldn't work so well So I revised it a little. This is what I have now.

Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
So I've just about got it complete except when the if statement is executed it adds a data row to other arrayList every time the item isn't CS. So I figured the best way to add a dataRow to the other arrayLists is only when CS isn't showing up in the 3rd column. So instead of doing something like this:



So I tried to do this



But that didn't work

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Don't use == true or == false, use direct comparison:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Dustin Schreader
Ranch Hand

Joined: May 25, 2009
Posts: 74
I got it working
 
wood burning stoves
 
subject: sorting an array from csv file.
 
Similar Threads
question on array and printing
Sorting question.
Unsolved Programming Problem. Need Help.
updating array elements
Query about compareTo() method