Comment on Tutorial - How to use ArrayList in Java By Hong



Comment Added by : alex

Comment Added at : 2010-06-13 05:35:34

Comment on Tutorial : How to use ArrayList in Java By Hong
Great Post! Thanks alot.

I 'm searching for a way to sum up the Values of a HashTable<String, Integer>

The Method you mentioned above

// get array
Object ia[] = al.toArray();
int sum = 0;
// sum the array
for(int i=0; i<ia.length; i++)
sum += ((Integer) ia[i]).intValue();
System.out.println("Sum is: " + sum);
}
}

is fine for ArrayLists but i cant get it work on HashMaps.
Any ideas how this could be done ?

BR Alex


View Tutorial



Ask a Question

Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Very Useful example, Thanks
View Tutorial          By: Prabhat Kumar Singh at 2011-12-21 20:44:00

2. Its really good and helpfull..........
chee

View Tutorial          By: sumit at 2009-04-28 05:17:17

3. its work well , thanks for code , but if any body
View Tutorial          By: mary at 2007-12-16 07:10:58

4. This is an old method although it works. The bette
View Tutorial          By: Emiley at 2013-01-11 03:56:02

5. This post is about adding an application icon to a
View Tutorial          By: Rick at 2011-11-04 16:48:16

6. I am doing a project to for sending sms from the s
View Tutorial          By: visalakshi at 2010-03-30 20:55:50

7. it is very good website for IT students
View Tutorial          By: jeecee at 2013-03-21 12:23:46

8. Thank you! Solved many headaches :)
View Tutorial          By: Dominik at 2013-07-30 16:51:46

9. Thnx.. it was clearly explained... tomorrow i have
View Tutorial          By: Susmitha Sen at 2012-03-25 09:34:29

10. Hi Shruti, If you have better samples then feel fr
View Tutorial          By: jagan at 2010-03-03 19:42:46