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



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. how to declare Array ?? in LINUX
i m try th

View Tutorial          By: Chand at 2012-03-18 06:47:09

2. awesome. thanks for the info
View Tutorial          By: Darren at 2010-05-09 19:55:22

3. Hi, I cant open the file after I click Write SD. I
View Tutorial          By: hassan at 2014-12-17 07:44:16

4. Thanks, much appreciated!
Saved a great dea

View Tutorial          By: alan at 2009-08-14 01:35:01

5. Thanks for the code. The code runs fine without an
View Tutorial          By: aanube at 2012-08-22 10:12:54

6. Hi ,

Since both the methods in the

View Tutorial          By: Chintan at 2013-11-21 03:42:32

7. Hi i changed some codes in that and i gave interne
View Tutorial          By: Göktuğ ÖZEL at 2013-03-13 22:44:55

8. Performance is low while working with BULK DATA
View Tutorial          By: kailash at 2009-07-17 06:11:55

9. super explaination
View Tutorial          By: santhish at 2011-07-06 05:00:54

10. Hi , instead of using localhost. I am using a mobi
View Tutorial          By: ashish at 2011-02-28 05:05:49