Originally posted by Carol Murphy:
I am floundering in a major way. I have code that reads the list in from the source file, and prints it in a list. I also have code that prints the contents of my ArrayList as an Array, just to prove to myself that my ArrayList is loaded with the names from the list. The Array prints out in this format:
[element1, element2, etc...]
First thing, am I on the right track?
Second thing, when I try to use sort(List) I get an error message stating that you can't convert void to char[]. Since my ArrayList is not empty.......
I tried to use Collections as my object to call sort, but I can't instantiate a Collections object because it has no constructor.
So.........
I'm kinda lost here. I can't call sort() because I don't have a Collections object, and the compiler thinks my ArrayList is void for some reason. HELP!!!
On the up side, my IO is working, at least I think it's working.
Collections.sort(nameofArrayList);
System.out.print(nameofArrayList.listIterator(0));
which delivers this line when I run the program:
java.util.AbstractList$ListItr@8212e99f
Exactly what is being printed by calling listIterator on my ArrayList?
Originally posted by Carol Murphy:
One more question before I hit the saloon- The objects stored in my ArrayList are Strings, right? So if I want to use String operations like indexOf() on each element, I should be able to do that, right???
Just wondering how to sort by last name.
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
"Happiness is a way to Travel, <b>Not</b> a Destination" -- Unknown
Originally posted by Carol Murphy:
I was thinking that since the code for loading the elements into the ArrayList was inside main ...
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Originally posted by Marilyn deQueiroz:
You should use a static block to initialize your ArrayList ... see the assignment for an example of a static block.
JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Matthew Phillips
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|