Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Mobile-Applications here we r getting the problem with ut data and get data????????????
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rajgopal
here we r getting the problem with ut data and get data????????????
1 Answer(s)      3 years and 10 months ago
Posted in : MobileApplications


private ArrayList keys; private ArrayList values;

  public Menus() {

    keys = new ArrayList();
    values = new ArrayList();
  }
  public java.util.Set keySet() {
        return new TreeSet(keys);

      }
   Hashtable<String,String> hash = new Hashtable<String,String>();
  public Object get(Object k) {
        int i = keys.indexOf(k);
        if (i == -1)
          return null;
        System.out.println("keys:" + keys + "values" + values);
        return values.get(i);
  }

 public Object put(Object k, Object v) {
        for (int i=0; i < keys.size(); i++) {
          Object old = keys.get(i);
          Enumeration keys = hash.keys();
          while (keys.hasMoreElements()) {
              Object key = keys.nextElement();
              Object value = hash.get(key);

              System.out.println(key+" : "+value);
            }
         // System.out.println("Key " + k+ "; Value " +
            //        v);
        }
        return k;
          }

Advertisement
View Answers

March 4, 2011 at 3:54 PM


java implementation of put and get method

import java.util.*;
public class Menus{
private ArrayList keys;
private ArrayList values;

  public Menus(){
    keys = new ArrayList();
    values = new ArrayList();
    }
  public java.util.Set keySet(){
    return new TreeSet(keys);
    }
  Hashtable<String,String> hash = new Hashtable<String,String>();
  public Object get(Object k){
        int i = keys.indexOf(k);
        if(i == -1)
         return null;
        return values.get(i);
    }
  public Object put(Object k, Object v){
        for(int i=0; i < keys.size(); i++){
          Object old = keys.get(i);
          Enumeration keys = hash.keys();
          while(keys.hasMoreElements()) {
              Object key = keys.nextElement();
              Object value = hash.get(key);
            }

        }
        keys.add(k);
        values.add(v);
        return k;
          }
          public static void main(String[]args){
              Menus menu=new Menus();
              menu.put("1","Rose");
              menu.put("2","India");

          System.out.println(menu.get("1"));
          System.out.println(menu.get("2"));
          }
}


Related Tutorials/Questions & Answers:
Advertisements
r
 

 

 

DMCA.com