Java 1.5 Syntax help

Posted on 2005-05-16
Medium Priority
Last Modified: 2010-03-31
Hello all,

What's the correct syntax for the declaration of:

1)  A public function (named "Fred")  that returns a double, and takes, as it's only argument, a Vector ((called "ethel") of Hashtables, where the hash key is a long, and the hash value is a Double?  I want to use the new generics, and I can't get this to work in Eclipse:

public double Fred(Vector<Hashtable<Long(), Double()>> ethel) { method body here}

2)  A foreach loop which loops through each hashtable in the vector "ethel" above, something like:

for (Hashtable<Long(), Double()> myHash: ethel) { stuff with myHash here}

Question by:vlg
  • 4
LVL 86

Accepted Solution

CEHJ earned 1000 total points
ID: 14013672
     public double fred(Vector<Hashtable<Long, Double>> values) {
            for (Hashtable<Long, Double> h: values) {
            return 0.0;
LVL 86

Expert Comment

ID: 14013684
Sorry - don't get confused between the function variable name and h.values() ;-)
LVL 86

Expert Comment

ID: 14013694
This would have been better as an illustration:

// Print the entries:

LVL 86

Expert Comment

ID: 14015351

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question