Mark Yadav

Greenhorn
+ Follow
since Aug 01, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mark Yadav

Hi All,
I've been having this recurring problem: I just can't configure the J2EE SDK 1.3 on a Win 2000 platform. I've gone through all the installation and configuration manuals on the Sun website and still no luck I've created two environmental variables: J2EE_HOME and JAVA_HOME with the values: C:\j2ee1.3 and C:\j2se1.3.1 which are the folders in which I downloaded the j2ee and the j2se SDK's respectively.
Could someone please give me a step-by-step instructions of how to configure the J2EE development kit because this is becoming frustrating
I tremendously appreciate any help you can give.
Thank you,
Mark Yadav.
Thanks so much Snigdia,
I'm not extremely expereinced in Java and I've been trying to expereiment with the language to get better skilled at it. Passing a Vector object into a HashMap was one way of expereinting. I've also tried to do the exercises out of various Java textbooks - would you recommend this approach? How did you increase your proficiency in Java?
Mark Yadav
16 years ago
Hi,

The problem I have is about passing one Collection object into another, such as passing a Vector object into a Hashmap. I've tried to do this in the two files included below: VectorToHash.java and VectorToHashTest.java.
The problem specification is: I put values into a Vector object and then passed it to a Hashmap and then I want to retieve those values out. I also want to associate each Vector object passed to the Hashmap with a Key object. I've made an attempt to do this below in the two .java files mensioned, but I'm stuck. Although the code does compile, I need help to correct it to work as specified. Could you help me correct my code, and help me understand what problem situations would require a Vector object to be passed to a Hashmap?

Many Thanks,
Mark Yadav.
VectorToHash.java
// VectorToHash.java - the purpose of theis class is to create methods
// that allow a Vector containing Strings to be added to a HashMap.
// The Test program: VectorToHashTest then returns the vector from
// the HashMap and then extracts the values from the vector.
import java.util.*;
public class VectorToHash {

// HashMap to store vector
HashMap book = new HashMap();
Vector v = new Vector();
String[] fruit = {"apple","banana","orange","tomato","pear"};
Integer[] id = new Integer[5];
// Method to add fruit to vector.
// A vector is then returned
public Vector addFruit(Vector v){
for(int i = 0; i < fruit.length; i++)
v.add(fruit[i]);
return v;
}
// method to add vector to HashMap. The retuned Vector
// from the previous method is added to the HashMap
public void addVector(Vector v, HashMap m){
for(int i = 0; i < 5; i++)
m.put(id[i], v);
}
}

VectorToHashTest.java
// VectorToHashTest.java Tests the VectorToHash class
import java.util.*;
class VectorToHashTest{
public static void main(String[] args){
// Vector object
Vector b = new Vector();
Vector c = new Vector();
// HashMap object
HashMap hp = new HashMap();
//
VectorToHash vth = new VectorToHash();
c = vth.addFruit(b);
// add vector to HashMap
vth.addVector(c,hp);
//output contents of HashMap
Set keys = hp.keySet();
Iterator keyIter = keys.iterator();
while(keyIter.hasNext())
System.out.println((Integer)keyIter.next());
}
}
16 years ago