File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Arrays in Hashtable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Arrays in Hashtable" Watch "Arrays in Hashtable" New topic

Arrays in Hashtable


Joined: Jun 20, 2001
Posts: 5
I am trying to store a list of students with their marks into a
hash table. When i try to show the students list , my marks array is having only the last student data. Rest all lost.
Class Student{
private String name;
private int marks [];
public Student (String _name, String _matricNum, int _marks[])
name = _name;
matricNum = _matricNum;
marks = _marks;
public int[] getMarks(){
return marks;

Class clas{
private Hashtable studhash = new Hashtable();
public void registerStudent
(String name, String matricNum, int marks[]){

Student s = new Student (name, matricNum, marks);
studhash.put(s.getName(), s );
public void showStudents(){
Collection coll = studhash.values();
Iterator i = coll.iterator();
while (i.hasNext()){
Student s = (Student);;
int[] rmarks = s.getMarks();
for (int i = 0; i < rmarks.length; i++){
System.out.println("Mark" + i + " " + rmarks[i]);



Public class Main{
String name, matricNum;
Class clas = new Class();
int[] marks = new int[2];

while (cont = true) {
name = getLineFromConsole("Name:");
matricNum = getLineFromConsole("MatricNumber:");
marks[0] = Integer.parseInt(getLineFromConsole("Marks1"));
marks[1] = Integer.parseInt(getLineFromConsole("Marks2"));

thanks in advance
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: Arrays in Hashtable
It's not a secret anymore!