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. There is possible to include 2 conditions in for l
View Tutorial          By: aarthi at 2012-12-10 12:08:50

2. I want to use the same code in c++,
Can a

View Tutorial          By: vijay at 2009-09-26 00:47:02

3. I tried this with HttpUnit (using the custom Hostn
View Tutorial          By: Michael Gower at 2012-01-04 17:40:00

4. please help me on "why subclass of stack is
View Tutorial          By: mahendra at 2012-12-15 03:39:22

5. Just what I was looking for. Thank you.
View Tutorial          By: Babool at 2008-05-08 08:32:50

6. this really helps me alot :)
View Tutorial          By: liezl at 2014-08-08 13:38:58

7. very Good machi.......
View Tutorial          By: Janani at 2013-03-04 06:37:47

8. Hello,
I've tried the above code, but I've

View Tutorial          By: Phyo Phyo at 2009-09-14 05:32:28

9. can we do it this procedure by iteration i know th
View Tutorial          By: sattar at 2010-05-03 03:00:20

10. i want source code of Send SMS on Mobile by Net.
View Tutorial          By: Ankit Patel at 2011-07-05 08:43:14