Share on Google+Share on Google+

rajgopal
here we r getting the problem with ut data and get data????????????
1 Answer(s)      6 years and a month 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;
          }

Ads

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"));
          }
}









Tutorials   
Java Spring Hibernate Struts Training How to uninstall old version of Android Studio? How to install cocoapods in Max? item lookup How to get path of a file in iOS? [NSConcreteMutableData release]: message sent to deallocated instance Covert Bool to String - NSString Getting UIButton by Tag How to write Example code for comparing Strings in iPhone SDK? How to set placeholder in uitextfield programmatically? Example code of adding placeholder in UItextFeild how to get UIView by tag J2me image use ase smiley UILineBreakModeWordWrap is deprecated Framework for Mobile Applications How to print UIButton id System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h' has been modified since the precompiled header UINavigationController Navigating to back uinavigationcontroller add right button UINavigationController how to set title uitextfield hide keyboard on return dismissmodalviewcontrolleranimated first deprecated in ios 6.0 xcode 6.1.1 download How to remove virtual keypad from apps java How to remove virtual keypad from apps java How to remove virtual keypad from apps java code to send sms alerts using jsp online iphone app development how to devlop mobile application? What is WAP? download mp3 file on server in iphone home button macbook pro keyboard calling from iphone through programitically in iphone How to retrieve a field from SQLite to Edittext in android How to retrieve a field from SQLite to Edittext in android Sqlite3 Why NSMutableDictionary ios work with nsdictionary what is class methods in objective c what is class methods in objective c UIButton HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE HOW TO FIND OUT GPS COORDINATES WITHOUT USING ONLINE DATABASE OR OTHERTHING ON MOBILE Rad Calculator ANDROID J2ME Bar graph j2me image application iphone iphone

Ads

 
Advertisement null

Ads