?
Solved

Java 1.5 Syntax help

Posted on 2005-05-16
4
Medium Priority
?
164 Views
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}


Thanks!
0
Comment
Question by:vlg
  • 4
4 Comments
 
LVL 86

Accepted Solution

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

Expert Comment

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

Expert Comment

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

// Print the entries:

System.out.println(h.entrySet());
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 14015351
:-)
0

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