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. Thanks for the tutorial,

I have a q

View Tutorial          By: rajendra at 2013-04-29 15:37:28

2. Excelent article, I will start to use struts 2 now
View Tutorial          By: Alex at 2010-01-20 16:13:34

3. Can any one say how to send a message to a particu
View Tutorial          By: Sankar guru.P at 2012-01-05 07:43:44

4. @readers
this is an example of Hiding and N

View Tutorial          By: DevJ at 2011-03-18 05:41:52

5. Thanks alot.. it helped me a lot...
View Tutorial          By: Sushmitha Rao at 2010-06-02 02:39:51

6. The tutorial is very usefull, i am happy now
View Tutorial          By: Haneefa at 2013-03-30 06:31:47

7. i Want Struts Full Details with
Word forma

View Tutorial          By: Kannan.R at 2007-10-04 00:40:27

8. Hi mate,
When I compile the DomParserExampl

View Tutorial          By: Suresh Kumar D at 2013-06-25 07:06:19

9. You only need 1 main method per application, not 1
View Tutorial          By: Michael at 2011-09-02 02:37:51

10. Thank you
View Tutorial          By: dara at 2009-12-19 02:46:52