Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7587731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:44:50+00:00 2026-05-30T19:44:50+00:00

I need to store some names into a vector and then convert that data

  • 0

I need to store some names into a vector and then convert that data into hashtable.The id of the hash table entry will be a serial no. What i did is

import java.io.*;
import java.util.*;

class VecToHash{
public static void main(String [] args){
Vector<String> vec = new Vector<String>(); 

Hashtable names=new Hashtable();
vec.addElement(new String("name1"));
vec.addElement(new String("name2"));
vec.addElement(new String("name3"));
vec.addElement(new String("name4"));
vec.addElement(new String("name5"));

int VecSize=vec.size();

for (int i=0;i<VecSize;i++){
for (int j=0;j<VecSize;j++){
names.put(("j"), new String(vec.elementAt(i)));
    }

Set set=names.keySet();
Iterator itr=set.iterator();

while (itr.hasNext()){
String str=(String) itr.next();
System.out.println(str+":"+names.get(str));}
System.out.println();
}}}

but its not taking the serial number as ID and i also to need to remove duplicates in Hastable. Please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:44:51+00:00Added an answer on May 30, 2026 at 7:44 pm

    Here is the right code.

    import java.util.ArrayList;
    import java.util.Hashtable;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Set;
    import java.util.Vector;
    
    
    public class Main {
    /**
     * @param args
     */
    /*public static void main(String[] args) {
        List<Integer> intList = new ArrayList<Integer>();
        intList.add(0, new Integer(1));
        intList.add(1, new Integer(1));
        intList.add(2, new Integer(1));
        intList.add(3, new Integer(1));
        intList.add(4, new Integer(1));
        intList.add(5, new Integer(1));
    
    }*/
    
    
    public static void main(String [] args){
    Vector<String> vec = new Vector<String>(); 
    
    Hashtable<Integer, String> names=new Hashtable();
    vec.addElement(new String("name1"));
    vec.addElement(new String("name2"));
    vec.addElement(new String("name3"));
    vec.addElement(new String("name4"));
    vec.addElement(new String("name5"));
    
    int VecSize=vec.size();
    
    for (int i=0;i<VecSize;i++){
    
    names.put(new Integer(i), new String(vec.elementAt(i)));
    }
    
    Set set=names.keySet();
    Iterator itr= set.iterator();
    
    while (itr.hasNext()){
    Integer temp = (Integer) itr.next();
    System.out.println(temp+":"+names.get(temp));}
    System.out.println();
    }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store some sensitive data by encrypting it with atleast 128 bit
I need to store some data in a Django model. These data are not
I usually use C++ stdlib map whenever I need to store some data associated
I have some things in my app that I need to store, in order
I am writing my first real applet and I need to store some data.
I am writing my first real applet and I need to store some data.
I need to download and parse some XML data, and to store it in
I need to store a large number of json feeds into Core Data. There
I'm creating an android application in which i will need to store data using
I need to store some simple properties in a file and access them from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.