English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

hello there
i'll get right to the point: i have to do a project, a java application, which is basically about students, their grades at different exams and so on

one of the last things which i am required to do is:
"replace the array of students from the class Exam with a collection of students"

i have absolutely no idea how to do this or even what this means!! i have checked out the tutorial about collection but still no idea

can anyone pleaase help? i'll be eternally grateful...

yours truly,
sheri

2007-01-03 02:35:33 · 2 answers · asked by lady xanax 3 in Computers & Internet Programming & Design

2 answers

you may use objects such as vectors,...
http://www.pekiyi.150m.com/java.html

2007-01-03 03:23:10 · answer #1 · answered by iyiogrenci 6 · 0 0

Actually it sounds so much harder that it really is! All you need to do is transform your array into another form like ArrayList or Vectors.
Here's an example:
- you have a String[] names = {"name1", "name2"};
Instead of using an array directly use an ArrayList and add the names.
ArrayList names = new ArrayList(); // creates the new array
names.add("name1");
names.add("name2");
- To get all the names you can have a simple loop:
for(int=i; i System.out.println((String) names.get(i)); // note: the .get method returns type Object so you will need to cast it to String for this example
}

There are also Maps, Tables,, etc. All extend the Abstract Collections class.
For more info on using things like array lists, check out http://java.sun.com/j2se/1.5.0/docs/api/ and look at ArrayLists. (but also look around for other collections. There are LOTS out there)
Hope this helps!

2007-01-03 12:55:20 · answer #2 · answered by Kinz 1 · 1 0

fedest.com, questions and answers