Retrieve key by value in Hashtable

Hello everyone,
I am wondering what is the most effective approach of retrieving key by value in a Java build-in Hashtable. Can anyone provide sample source codes?
Thanks in advance,
George

there is something I want to ask about hashtable also , please see this source code
import java.io.*;
import javagently.*;
public class Students
    static final int nMarks = 6;
    String name = "";
    int marks[] = new int[nMarks];
    int finalMark = 0;
    int weights[] = { 5 , 10, 5, 15, 15, 50 };
    void setMarks(BufferedReader in) throws IOException
        for(int i = 0 ; i < nMarks ; i++)
            marks[i] = Text.readInt(in);
    void setName(BufferedReader in) throws IOException
        name = Text.readString(in) + " " + Text.readString(in);
    void calculateFinal()
        for(int i = 0 ; i < nMarks ; i ++)
            finalMark += marks[i] + weights;
finalMark = finalMark / 100;
import java.io.*;
import java.util.*;
import javagently.*;
public class Marker
    public static void main(String args[]) throws IOException
        BufferedReader in = Text.open(System.in);
        BufferedReader fin = Text.open("C:\\brandnew\\marks.txt");
        Hashtable table = new Hashtable(10);
        for(int i = 0; i < 4 ; i++)
            Students student = new Students();
            student.setName(fin);
            student.setMarks(fin);
            student.calculateFinal();
            table.put(student.name, new Integer(student.finalMark));
        System.out.println("In the table are ");
        for(Enumeration e = table.keys(); e.hasMoreElements();)
            String name = (String)e.nextElement();
            System.out.println(name);
        while(true)
            try
                System.out.print("Whose mark do you want to know? ");
                String s = Text.readString(in) + " " + Text.readString(in);
                if(table.containsKey(s))
                    Integer result = (Integer) table.get(s);
                    System.out.println(result.intValue());
                else
                    System.out.println("Sorry try again!!!");
            catch(EOFException e)
                break;
}Worry not for javagently, it is an extra package to simplify input and output... The problem I want to ask here is , I got error when trying to execute the code
java.io.EOFException
at javagently.Text.refresh(Text.java:116)
at javagently.Text.readString(Text.java:109)
at Students.setName(Students.java:23)
at Marker.main(Marker.java:18)
Exception in thread "main"
I checked the source code and there is nothing wrong...

Similar Messages

  • WD for Java: How to I retrieve key and value for DropDownbyKey selection

    Dear All
    I thought this was going to be straightfoward and am obviously missing something.
    I have created a simple modifiable value set to create a dropdown list to select a country:
      public void GetCountryDropDownValues( )
        //@@begin GetCountryDropDownValues()
        Y_Tf_Npf_Get_Countries_Input countriesInput = new Y_Tf_Npf_Get_Countries_Input();
        wdContext.nodeY_Tf_Npf_Get_Countries_Input().bind(countriesInput);
        try {
              countriesInput.execute();
              wdContext.nodeY_Tf_Npf_Get_Countries_Input().nodeOutput_countries().invalidate();
         } catch (WDRFCException ex) {
              // TODO: handle exception
        IPrivateNonPersonalisedLearnAdminReq.IContextElement elem = wdContext.currentContextElement();
         String strObjElem0 = elem.COUNTRY;
         IWDAttributeInfo i_ObjType0 = wdContext.getNodeInfo().getAttribute(strObjElem0);
         ISimpleTypeModifiable w_ObjType0 = i_ObjType0.getModifiableSimpleType();
                   IModifiableSimpleValueSet s_ObjType0 = w_ObjType0.getSVServices().getModifiableSimpleValueSet();
                   s_ObjType0.clear();
         for(int i=0;i<wdContext.nodeEt_Countries().size();i++)
                      IPublicNonPersonalisedLearnAdminReq.IEt_CountriesElement elemOrg = wdContext.nodeEt_Countries().getEt_CountriesElementAt(i);
                        s_ObjType0.put(elemOrg.getLand1(),elemOrg.getLandx50());
        //@@end
    This is bound to a new context element attribute:
    Country of type string
    When value is selected from dropdown, it is stored in string
    What I want to be able to do is to retrieve the text as well as the key from the selected object.
    At the moment I can only return the key.
    i.e.  wdContext.currentContextElement().getCountry();
    Any pointers will be greatfully received and maximum points awarded to the first complete
    answer that works for me.
    Many thanks in advance
    Mike

    Hi,
    You can use the following code.
    ISimpleValueSet valueset = attInfo.getModifiableSimpleType().getSVServices().getValues();
    if(valueset.containsKey(key)){           // Give your key here, which you already know to retrieve
    String value = valueset.getText(key);             // Here you will get the value
    Hope it helps.
    Regards,
    Manoj

  • Hashtable - Retrieving the two values

    Lets say i have a hashtable as follows
    Hashtable Dictionary = new Hashtable();
    for(int code=0; code<256; code++)
          Integer value = new Integer(code);
          Integer key = new Integer(code);
           Dictionary.put(key, value);
    }How can I point to an index of the hashtable and either retrieve key or value as in...
    Dictionary.get(i).value or Dictionary.get(i).key

    ArrayList<Map.Entry> ame = new ArrayList<Map.Entry>(myHashTable.entrySet());
    Map.Entry<Integer,Integer> me = ame.get(index);
    Integer key = me.getKey();
    Integer value = me.getValue();

  • Writing the hashtable content (both keys and values) into a text file

    Hello,
    I have a hashtable which have some keys and respective values in it. Now I want to write all thoses content into a text or log file. Can anyone please tell me how to write it.
    thanks,
    chaitanya

    Properties is a subclass of Hashtable. It'll probably work just fine as a drop-in replacement.
    Otherwise...if all keys and values are text, then loop through the Entry objects in the Map in question (Hashtable is a Map, and you probably shouldn't be using Hashtable anyway), or loop through the keys and grab the corresponding value for the keys. Read the API docs for java.util.Map. It's pretty straightforward.

  • Convert hashmap (containing null values) to hashtable

    hi
    the following code gives me java.lang.NullPointerException
    how can i convert a hashmap ( contaiing null values ) to hashtable... ??
    and vice versa ?
              HashMap hm =new HashMap();
              hm.put("1","one");
              hm.put("2","two");
              hm.put("3","three");
              hm.put("4",null);
              Hashtable ht = new Hashtable(hm);how ever the code will run perfectly well if i remove
                   hm.put("4",null);Regards
    Lav

    so does that mean that theres is no way to convert a
    hashmap containing null values to hashtable ..!!There are several ways described above.
    If you mean is there a way to preserve the nulls as nulls, then, no, you cannot do that, because, as stated in the docs, null cannot be a key or value in a Hashtable.

  • Retrieving Key from array

    Hi
    I need a dynamic way of retrieving all the "keys" from a array.
    Found this which is exactly what I need but doesn't work as expected in my case:
    var myObject:Object = {key1:"value1",key2:"value2"}
    for (var s:String in myObject)
    trace("key:",s,"value:",myObject[s]);
    //key: key2 value: value2
    //key: key1 value: value1
    My case:
    var testArray:Array = new Array()
    testArray = DG1.dataProvider.toArray() // create array from dataprovider
    I've tested this array and it performs "correctly" as an array but when I try the above mentioned method it traces as follows:
    key: 0 value: [object Object] (key not being what I need)
    What I need:
    dgArr.push({partNo:event.target.data['partNo'+i],description:event.target.data['descriptio n'+i],cost:event.target.data['cost'+i]});               
    trace (????) //outputs = partNo, description, cost etc...
    Thanks for any help.

    your dataprovider values are also objects.  use:
    function listF(dp:DataProvider):void{
    for(var i:int=0;i<dp.length;i++){
    for(var s:String in dp.getItemAt(i)){
    trace(s,dp.getItemAt(i)[s]);

  • Error in key figure value at Reporting level

    Hi Experts,
    I had problem of Key figure value which displays wrong data in reporting.
    The Process is :
    I had added the key figure SALK3 to the generic data source (xxx). The Extractor is Table/View, Table is MBEW.I had replicated to BW side.
    In BW, The process is Data Source(Generic) to 0MAT_PLANT(Infoobject (Added SALK3 to the infoobject of Attributes tab) ) loads to Multiprovider.I can see data  in the multi provider for that particular field after loading.
    Now the problem is, In Query designer i had added the key figure in Columns and ran the report.The output of the field is, If the value is 100 it displays 100 ERROR, if it 200 it displays 200 ERROR.Could you please help me on this,where i went wrong.
    Regards,
    Kishan.

    Hello,
    Please check with the follwing screen shots:
    Right click on the key fgure you created----select edit
    Once the screen opens select the NODIM from Data Functions before the key figure (as highlighted).
    Finally click on OK.
    Regards
    NS

  • Key figure value in a level

    Hi is it possible to identify which key figures values has introduce a user ? and which CVC has the user uses for inserting the key figure value?
    REgards.
    PS :We have APO DP 5.0

    Javier,
    It is possible to identify and track the inputs of specific users contribution to that Key figure using the following method, Provided you follow certain prerequisites first.
    Its should be known before the certain people are responsible for certain data selections, like if there is a change in certain Sales org, we should ideally know who is the assinged planner to that Sales Org. or that sales org has been assinged to which Planner
    Next, Develop to Lag reports in BI using the regular snapshots of the the data extracted out of DP before and after the changes have been made for that particular KF.
    Compare the changes using the versions of snapshot before changes and after changes, or perhaps create another calucalted KF showing the different between two versions. The BI team should be able to create reports that enable you to run this report on all levels for that Key figure.
    Hari V

  • Key Figure value in Cube showing with extra zeros

    Loaded data into the cube. When I display the result
    Key figure values are showing with 2 extra zeroes and Quantity value shaowing with 3 extra zeroes.
    Original value
    Price, Quantity, Sales Rev
    2     1     2
    3     2     6
    When display value from cube
    Price, Quantity, Sales Rev
    2,00     1,000     2,00
    3,00     2,000     6,00
    Why zero is showing? How can I display the original value? In PSA, values are showing correctly.
    Thanks,

    Hi,
    These are the zeroes after the decimal places. this is the property of the key figure.
    In your report you can change the display value. In the display properties of the Key figure under the number of decimal places make it as 0. This will remove the zeroes.
    Hope it helps.
    Regards,
    Gaurav
    Edited by: Gaurav Kothari on Oct 16, 2008 10:35 AM

  • Retrieving old column values from a after delete trigger dynamically

    I have a single audit table for deletions
    and the table structure has the following columns
    1: table_name
    2: column_name
    3: column_value
    I am writing a trigger on tables for which i want to have delete audits and i am dynamicaly
    retrieving the column names but i am unable to retrieve the column value dynamically;
    I tried to use the following statement but doesn't return the column value
    sql_stmt:= 'select :1 from dual';
    execute immediate sql_stmt into col_value using
    ':old.'| |v_col_name;
    where v_col_name is the name of the column which i retrieve dynamically using the
    dbms_sql.describe_columns procedure.
    Is their any way if i can retrieve the old column values in the trigger dynamically if i already
    have the column names in variables..
    Thanks in advance.
    null

    I don't know if Kevin's tip Help Mr. Sameer, but it did help me gain access to pre-deleted row column values.
    I did discover, however, that if the columns from the about-to-be-deleted row are used as inserts into another table, Oracle serves up a nasty-gram informing the user that values from the about-to-be-deleted table are unreliable.
    I was able to circumvent this constraint by assigning the about-to-be-deleted column values to local PL/SQL varables, then perform the insert using the variable values.
    -Bill McNamee
    NHDOT
    [email protected]

  • MDM Exception: Key mapping value must be unique. You cannot overwrite key

    "ServerException: Key mapping value must be unique. You cannot overwrite key mapping values."
    I received such exception when code tried to manipulate Key Mappings of the record.
    error was not happen on mdm 5.5 but on 7.1 it sometimes appears.
    What is probable reason of this?
    How to resolve this ?
    Code is approximate so:
                                         String[] keys = keyMapping.getKeys();
                        if (recordKeyMapping.containsKeyMapping(remoteSystem)) {
                    recordKeyMapping.replace(remoteSystem, keys);
              else {
                   recordKeyMapping.addKeyMapping(keyMapping);
              //Persist
              targetRecord.update();
    //where methods are:
         public void replace(RemoteSystem remoteSystem, String[] keys) {
              KeyMapping keyMapping = getKeyMapping(remoteSystem);
              if (keyMapping == null) throw new IllegalArgumentException("Can't update keys: key mapping for the system '" + remoteSystem + "' is not found");
              else {
                   keyMapping.setKeys(keys);
         public void addKeyMapping(KeyMapping keyMapping) {
              RemoteSystem remoteSystem = keyMapping.getRemoteSystem();
              for(int i = 0; i < keyMapping.size(); i++) {
                   addKey(remoteSystem, (String) keyMapping.get(i));
    Edited by: Vladimir Grigoryev on Oct 5, 2010 11:26 AM

    Hello -
    I am not sure on that coding part. but is it like are you trying to retrive Key Mapping from Memory accelerator. Here this information always needs to be read from Database.
    I am sure you also maintained  the required attribute for key mapping as in Property in Console should be set as "Yes" and other relevant things properly .
    Here also go through the below link for more insight from tools perspective.
    http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/30843106-5539-2b10-75a9-da483911b0d9
    http://help.sap.com/javadocs/mdm/sp06/com/sap/mdm/data/KeyMapping.html
    It may help
    Rgds
    Deep

  • How to retrieve a property value from an iview in the back-end?

    Hi,
    I am looking for a back-end function module or any other way to retrieve the property value of an iview in the portal.
    Is this possible?
    thanks,
    Bert Caryn

    Hi,
    Look at the following threads,
    For programmatically getting the iview properties,
    Programmatically getting iView Properties
    Also,
    Get Properties of IView Programmatically
    Permanent change of iView property programmatically
    Hope these threads help u.
    Regards
    Srinivasan T

  • Key Field Value for File Adapter Sender Wildcard

    Hello everybody, is there a way to use a wildcard for the property of NamA.keyFieldValue in the cc for a Fils Sender????, here's an example why, I need to take some Files via PI 7.0 and my key filed can change according to the file an example is that in a file can be HF28 and in another file can be HF29, the only character that is going to be constant is the H, I would really appreciate any suggestions, thanks in advance.
    Regards,
    Julio Cesar

    Hi Julio
    File sender adapter will read the file using FCC
    Key Field Value entry is mandatory if the key field name is set. Otherwise, the entry can be ignored
    http://help.sap.com/saphelp_nw70/helpdata/EN/34/393071e9b998438ddb8ce97cd617a1/frameset.htm
    Content Conversion ( The Key Field Problem )
    Thanks
    Gaurav Bhargava

  • Wild Card as key field value in Content Conversion

    Hi,
         Can any one please tell me that can a wild card such as '*' be used as key field value.
    Thnx,
    Pravesh Puria.

    Hi Pravesh
    For the file name in the sender file adapter you can use the '*' or '?'(as a placeholder for exactly one character)
    You can also enable the "Advanced Selection for Source File" in the sender file adapter, where you can do two things:
    a)you can specify an exclusion mask for the file name specified above.
    b)you can specify/lits multiple directories with a file name and an associated exclusion mask, e.g. in file name you put ".txt" and in the associated exclusion mask "a". The every file with ".txt" except "a" will be fetched from that directory. 
    Try it out.
    Regards,
    Goekhan

  • Key Field Value in FCC

    Hi Experts,
    I have a scenario in PI, where I have 1 Header, n Data Records and 1 Trailer in the source file. This data is coming in CSV format.
    I am using FCC to convert CSV into XML.
    In the FCC, I have used keyFieldValue parameter. For the Header Record, the Key Field Value is constant "H"; for Trailer Record the key field value is constant "T".
    However for Data Record, the key field value is not constant. The first character of Key field of Data Record will always be "D", but rest of the Alphabets can change.
    Sample File:
    "H","3.04",22/10/2009,16:31:12
    "D2S",21/10/2009,20:00:26,"20044",00666,"S",1
    "D2S",22/10/2009,14:26:20,"20044",00668,"S",1
    "D0S",22/10/2009,08:33:34,"00044",04165,"S",1
    "D0S",22/10/2009,11:59:59,"00044",04166,"S",1
    "T",1393.27,1393.27,8
    Here, first line is Header Line (Key Field Value "H"), Last Line is Trailer Line (Key Field Value "T") and all lines in between Header and Trailer are Data Records (Key Field Value starts with "D). I need to convert this file into XML.
    I have no clue, if this can be converted into XML through FCC.
    Any help will be highly appreciated.
    Regards,
    Varun

    >
    Varun Agarwal wrote:
    > Sample File:
    >
    "H","3.04",22/10/2009,16:31:12
    > "D2S",21/10/2009,20:00:26,"20044",00666,"S",1
    > "D2S",22/10/2009,14:26:20,"20044",00668,"S",1
    > "D0S",22/10/2009,08:33:34,"00044",04165,"S",1
    > "D0S",22/10/2009,11:59:59,"00044",04166,"S",1
    > "T",1393.27,1393.27,8
    >
    > Here, first line is Header Line (Key Field Value "H"), Last Line is Trailer Line (Key Field Value "T") and all lines in between Header and Trailer are Data Records (Key Field Value starts with "D). I need to convert this file into XML.
    >
    > I have no clue, if this can be converted into XML through FCC.
    > Any help will be highly appreciated.
    >
    >
    > Regards,
    > Varun
    Write a simple module. The module will do a replace of the Dxx fields to D (you can use simple regex function for this)
    After the module, use the messagetransformbean to do the FCC for you.
    The module might sound complex, but trust me its a simple logic you need to implement and you can easily do the FCC with the messagetransformbean

Maybe you are looking for