Hashtable---getting value

import java.util.*;
import java.text.SimpleDateFormat;
class Test{
     public static void main(String[] args)throws Exception{          
          String Holidays_val = "1/25/207|SecondHolidayDay^2/01/2007|Anotherholiday^3/01/2017|newholiday^4/02/2007|someotherholiday^5/03/2007|Firstholiday^";
          String date1="";
          String holiday1="";
          StringTokenizer str1 = new StringTokenizer(Holidays_val,"^");
          Hashtable hs = new Hashtable();
          Date dates[] =new Date[5];
          int m=0;
          while(str1.hasMoreTokens()){
               String st1 = str1.nextToken();
               StringTokenizer stk = new StringTokenizer(st1,"|");
               while(stk.hasMoreTokens()){
                    date1 = stk.nextToken();
                    holiday1 = stk.nextToken();
                    dates[m] = new Date(date1);
                    m++;
               hs.put(date1,holiday1);     
          Date temp = null;          
          for(int i=0;i<dates.length;i++){               
               for(int j=i+1;j<dates.length;j++){     
                    if(dates.after(dates[j])){
                         temp = dates[j];
                         dates[j] = dates[i];
                         dates[i] = temp;
          SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
          Vector dates1 = new Vector();
          for(int k=0;k<dates.length;k++){               
               dates1.addElement(dateFormat.format(dates[k]));
          Iterator iter1 = dates1.iterator();
          Vector finalVec = new Vector();
          while(iter1.hasNext()){
               String date = iter1.next().toString();
               finalVec.addElement(date);
               finalVec.addElement(hs.get(date));     
               System.out.println(date);// printing the date CORRECTLY
               System.out.println(hs.get(date));//printing the corresponding holiday as NULL, when i place a hardcode date as hs.get("2/01/2007")---its printing the holiday name correctly.
               //GETTING NULL IN THE ABOVE LINE OF CODE, i should get the corresponding holiday name of the given date
               System.out.println(finalVec);
In the above code im taking the String Holidays_val, im separating the date and their corresponding holiday names, and then im sorting the dates and placing the dates and holidayname in a hashtable. finally im placing the date and its corresponding holiday in the vector, but the problem over here is im getting the null in case of corresponding holiday while putting in Hashtable.

Is this a joke?
Why are you turning the strings into dates, and then back into strings again?.
Even if the strings at both ends of the process are identical, it's a strange thing to do.
You should key the hashtable off of the Date objects.
Other issues:
You're using a deprecated constructor for Date. Use java.text.SimpleDateFormat to parse the date string and get a Date object.
Drop that whole thing when you turn dates back into strings.
Why do you add things to arrays, and then put them into vectors? Just add the Date objects directly into a vector.
But better yet, don't use Vector. Use a more modern List implementation, like ArrayList. And use a HashMap rather than a Hashtable.
And write to interfaces; the types of variables should be List and Map, not Vector or Hashtable (or ArrayList or HashMap).
Don't do the sort yourself. Use java.util.Collections.sort.
And you don't really need a separate List and a Map. Just use a SortedMap.
You can do this whole thing in less than half the code, and it'll work better too.

Similar Messages

  • Over riding hashtable get and put method

    Hi all
    Anyone have any idea about over ride HashTable get() and put(). Is it possible to over ride HashTable methods.

    Yes_me wrote:
    I want to change the structure of the java HashTable get and put method. As put method is having two object parameters I want to send one more parameter as String to it. Is it possible to change the structure in this way.What would you want to be returned when calling get()? I would go with the suggestion to create a class to keep that information. If you really want to, you can completely hide that information class inside your extended HashTable. You could create an overloaded put method that takes three parameters and then creates an instance of the information class and put that into the map. If you only want the data for display only, the get method could get the information class mapped to the given key, then simply return a nicely formatted String containing the two values.

  • HELP! I need help to understand how to get value on radio buttons!

    hello,
    I realy need the help from anyone that knows how to get value from radio buttons in a JSP.
    I have this :
    <%
    java.util.Vector vLinha = (java.util.Vector) datos.get("ConsNefect");
              java.util.Hashtable ordens;
              java.util.Enumeration eLinha = vLinha.elements();
              String t = "radio";
              String x = "escolha";
              String l = "";
    int i = 0;
              //int esc = 0;
    String fila = "";                         
              boolean bol = true;
    while (eLinha.hasMoreElements())
    ordens = (com.ibm.dse.base.Hashtable) eLinha.nextElement();     
              if (++i%2 == 0)
    fila = "formgriscla";
    else
    fila = "formgrisosc";
    out.println("<tr>");
    out.println("<td class=\"" + fila + "\">");
    out.print("<p class=\"dato2\">");          
              out.print("<a href=" + urls.get("action"));
         out.print("&sequencia=" + (String) ordens.get("sequencia"));                    
         out.print(">");
              out.print((String) ordens.get("descricao"));
         out.print("</a></p></td>");
              out.println("<td class=\"" + fila + "\">");
    out.print("<p class=\"datop\">");          
              out.print((String) ordens.get("datap"));
    out.print("</p>");
    out.println("<td class=\"" + fila + "\">");
    out.print("<p class=\"datop\">");
    out.print((String) ordens.get("erro"));
              out.print("</p>");
              out.println("<td class=\"" + fila + "\">");
              out.print("<p class=\"datop\">");     
              l = (String) ordens.get("sequencia");     
              out.println("<input type=\"" + t + "\" name=\"" + x + "\" value=\"" + l + "\">");          
              out.print("</p></td>");      
              out.println("</tr>");
              //esc++;
    %>
    <!--input type="Hidden" name="escolha" value=<!--%l%>-->
    <!--input type="Hidden" name="escolha" value="<!--%=escolha%>"-->
    </td>
    </tr>
    I don�t know how to take the value... PLEASE HELP ME OUT!
    THANKS TO ALL!,
    Best wishes,
    Alex (portugal)

    You must wrap your contents into a FORM element and, then, using getParameter("escolha"), retrieve your value.

  • How to get value by running  in code behind?

    Hi all,
    i am running one stored procedure which return value.
    i am calling that stored procedure like this.
    Dim retvalue As Integer
    dtformat.ShortDatePattern = "MM/dd/yyyy"
    Dim YourDate As DateTime = Convert.ToDateTime(dt, dtformat).ToString("MMM/dd/yyyy")
    Dim hsh As New Hashtable
    objDataTier.OpenDbConnection()
    con1.Open()
    Dim oc As New OracleCommand("spSelectStartDay")
    oc.CommandType = CommandType.StoredProcedure
    oc.Parameters.Add("v_pidate", OracleType.DateTime).Value = dt
    retvalue = oc.Parameters("v_poRetval").Value.ToString()
    but not getting value in retvalue variable?
    how to get the value in that.
    my stored procedure is here.
    create or replace
    Procedure spSelectStartDay
    v_pidate IN DATE DEFAULT NULL ,
    v_poRetVal OUT NUMBER
    AS
    v_dpart NUMBER(10,0);
    v_date DATE;
    v_startweek NUMBER(10,0);
    BEGIN
    v_dpart := TO_Char(v_pidate,'DD') ;
    v_dpart := v_dpart - 1 ;
    v_date := Trunc(Trunc(v_pidate, 'MM')+1,'MM');
    v_startweek := TO_CHAR(to_date(v_date, 'dd-MM-yy'), 'd');
    v_poRetVal := v_startweek ;
    RETURN;
    END;
    thanks

    You need to add both parameters. You should create the parameter, then specify a direction. In C# (taken from a script that executes an anonymous block, but will work for your purposes)
                    using (OracleConnection oCon = new OracleConnection(_connectionString))
                        oCon.Open();
                        using (OracleCommand oCmd = new OracleCommand())
                            oCmd.Connection = oCon;
                            oCmd.CommandType = CommandType.Text;
                            oCmd.CommandText = sql;
                            oCmd.BindByName = true;
                            OracleParameter opS = new OracleParameter("p_s", OracleDbType.Varchar2, 100, s, ParameterDirection.Input);
                            OracleParameter opC = new OracleParameter("p_c", OracleDbType.Int32, c, ParameterDirection.Input);
                            OracleParameter opA = new OracleParameter("v_a", OracleDbType.BinaryDouble, ParameterDirection.InputOutput);
                            oCmd.Parameters.Add(opS);
                            oCmd.Parameters.Add(opC);
                            oCmd.Parameters.Add(opA);
                            oCmd.ExecuteNonQuery();
                            a = double.Parse(oCmd.Parameters["v_a"].Value.ToString()); // note there are better ways to do this... it's quick and dirty to parse the string value.

  • NOT Getting Values for LOCATION...on MultiProvider REPORT

    HI All,
    I have a MultiProvider on 4 cubes.All these 4 cubes having object LOCATION. I can see data in all cubes for LOCATION. I am running a report on this MultiProvider.
    Problem:
    I am not getting Values for LOCATION. Why?
    What I did:
    I checked all location objects of all 4 cubes @ MultiProvider level .
    I didn't use any Infoprovider in Qry designer sections.
    Please suggest. What is the reason how to solve..
    THanks & Regards.
    Sri.
    Edited by: siri26 k on Dec 5, 2008 10:41 AM
    Edited by: siri26 k on Dec 5, 2008 10:41 AM

    hello,
    in the identification tab of the MP,make sure you have checked all four checkboxes across the 4 infoproviders.
    then in Listcube T-Code, select your MP,display the records based on selection inputs and see if location is populated.
    If the data is not coming in listcube, then it will not come in the Query too.
    Reg,
    Dhanya

  • Not getting values in the variable

    Hi experts,
    in  this program  
    i want VBPA-vbeln = xblnr....but there is a data length error. so I ahve declare one variavble of length 10. & i am moving this xblnr to this variable but not getting value in that variable that i am moving..& give me the possible solutions...
    when '0FI_AR_4'.
             data: t_DTFIAR_3 like DTFIAR_3 occurs 0 WITH HEADER LINE.
              data: BEGIN OF t_DTFIAR_3 occurs 0.
                      include structure DTFIAR_3.
              data:        xblnr1(10).
              data: END OF t_DTFIAR_3.
              data : BEGIN OF t_partner occurs 0,
                         VBELN like vbpa-VBELN,
                         parvw like vbpa-PARVW,
                         kunnr like vbpa-kunnr,
                     END OF t_partner.
            data : xblnr1(10).
    t_DTFIAR_3[] = C_T_DATA[].
      move t_DTFIAR_3-xblnr to t_DTFIAR_3-xblnr.
                select VBELN PARVW kunnr
                       into table t_patner
                       from vbpa
                       FOR ALL ENTRIES IN t_DTFIAR_3
                       where VBELN = t_DTFIAR_3-xblnr.
    SORT t_partner BY VBELN PARVW.
              loop at t_DTFIAR_3.
                 loop at t_partner where VBELN = t_DTFIAR_3-xblnr1.
                       if t_partner-PARVW = 'ZA'.
                           t_DTFIAR_3-YPARVW1 = t_partner-PARVW.
                           t_DTFIAR_3-YPART1 = t_partner-kuNNR.
                       elseif t_partner-PARVW = 'ZR'.
                           t_DTFIAR_3-YPARVW2 = t_partner-PARVW.
                           t_DTFIAR_3-YPART2 = t_partner-kuNNR.
                       ELSEif t_partner-PARVW = 'ZE'.
                           t_DTFIAR_3-YPARVW3 = t_partner-PARVW.
                           t_DTFIAR_3-YPART3 = t_partner-kuNNR.
                       ELSEif t_partner-PARVW = 'ZS'.
                           t_DTFIAR_3-YPARVW4 = t_partner-PARVW.
                           t_DTFIAR_3-YPART4 = t_partner-kuNNR.
                       ENDIF.
                       MODIFY t_DTFIAR_3.
                endloop.
              ENDLOOP.
              C_T_DATA[] = t_DTFIAR_3[] .
    Thanks in advance

    HI,
    While moving use the WRITE TO option.
    WRITE VBPA-vbeln TO xblnr.
    Regards
    Sudheer

  • Using bean.variable for inputText but not getting value

    Hi I am using ADF BC JSF 10.1.3.2.
    I have a search page that has : dropdown1,
    based on dropdown1, I populate the dropdown 2 and with autosubmit and partialtrigger and also set either of the two search layouts true
    LAyout 1 based on dropdown1 value, say x, is rendered and I have 3 inputText , each have value= #{backingbean.variable}.
    Now when i am running this page, I got dropdown2 rendered with correct values and layout 2 rendered as required. Problem starts when I enter a value in the inputText1 and click on search button. In the search method, I try to get value for variable with so many ways : getVariable(), this.getInputText1.getValue()/// All these returned null.
    I tried to initialize the variable. In this case, the inputText1 showed initialised value and when i change value and submit, in the search method I still get the old initialised value.
    The inputText1 somehow never sets the value
    Please help..
    Regards
    Sudha

    Hi,
    I'm not exactly sure about what your functionality is but from what I gather the problem could be that if the bean is request scope then the value of the input text is already lost when you are trying to retrieve it.
    In any case I think that the best thing to do is to use the default view criteria functionality to perform the search if it is done on a view object.
    Gabriel.

  • From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    Hi,
    Use NVL or COALESCE:
    NVL (col_a, col_b)
    Returns col_a if col_a is not NULL; otherwise, it returns col_b.
    Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
    For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Unable to get value of the property 'nodeName': object is null or undefined  Error in apex_ns_3_1.js

    I am getting the following error with IE9 and Firefox 26 with application express 3.2:
    SCRIPT5007: Unable to get value of the property 'nodeName': object is null or undefined
    apex_ns_3_1.js, line 589 character 10
    this.dialog.check2 = function (e){
    var tPar = html_GetTarget(e);
    var lEl = $x('apexir_col_values_drop');
    var l_Test = true;
    ******  while(tPar.nodeName != 'BODY'){
    tPar = tPar.parentNode;
    if(tPar == lEl){l_Test = false;}
    if(l_Test){$x_Remove('apexir_col_values_drop')}
    This happens when I click the Gear Icon, then Filter, then I click the dropdown arrow under expressions and pick an expression from the list.
    If I set (through IE Developer tools) back to IE8 mode, I don't get the error.

    Guess no one is using 3.2 any longer or no one else gets this error.....  Guess I can edit the JavaScript file to trap the error since it really doesn't seem to cause an issue.  Just didn't want to have to go that route.

  • Getting values from a datagrid to an ArrayCollection

    Hi, I have a drag and dropable datagrid. I fill it with rows of data from another datagrid. Finally, my application demands savings the data from the datagrid into an array collection along with the index of each row. How do i get values from a datagrid into an arrayCollection variable? Please help me..!

    Whatever is dropped into the DataGrid automatically goes into its dataProvider property, typically an ArrayCollection. Just access the data grid's dataProvider property to see the values.

  • Can you get values back from a stored procedure via OUTPUT parameters?

    Can you get values back from calling a stored procedure via OUTPUT parameters/variables? I call the SP via a SQL statement from a script either in a WF or DF.
    I thought I read some reference that DI could not get the values from OUTPUT parameters but I could not find it again (don't know if it is in any of the documentation or referred to in a forum.
    I did try a couple of tests but it did not reutrn any values via OUTPUT. But before I give up I thought I'd see if you could and maybe I needed to change something.

    This isn't exactly an answer to your question, but I'll point out that, given that you're resorting to a SQL script in the first place, there's no reason you can't also turn the output parameters into a regular result or record set. (The following uses T-SQL, although I think it's pretty generic.)
    declare @param1 int, param2 varchar(100), @return int;
    exec @return = proc @param1 = @param1 output, @param2 = @param2 output;
    select @param1 as param1, @param2 as param2;
    That is, to get from output parameters to a "regular" output from the SQL script isn't much of a leap...
    Jeff Prenevost
    BI Consultant
    Ann Arbor, MI

  • How to get values from a stored package variable of type record ?

    Sir,
    In my JClient form, I need to get values from a database stored package variable of type record. And the values are retained in the JClient form for the whole session. The values are copied only once when the form is started.
    What is the best way to do that ?
    Thanks
    Stephen

    Stephen,
    not sure what your model is, but if it is Business Components, I think I would expose the properties as a client method on the application module. This way all JClient panels and frames will have access to it. You could use a HashMap to store the data in teh app module.
    If JDBC supports the record type, then you should be able to call it via a prepared SQL statement. If not, you may consider writing a PLSQL accessor to your stored procedure that returns something that can be handled.
    Steve Muench provides the following examples on his blog page
    http://otn.oracle.com/products/jdev/tips/muench/stprocnondbblock/PassUserEnteredValuesToStoredProc.zip
    http://otn.oracle.com/products/jdev/tips/muench/multilevelstproc/MultilevelStoredProcExample.zip
    Frank

  • Getting values from a stored procedure with no parameters

    Hi,
    I'm trying to get values out of a stored procedure that I created on SQL server. I'm trying to get XML values out of the database, but I'm not sure how to get any data out of it written to a file if the procedure doesn't have any parameters.
    So I'm just making a call:
    CallableStatement cs = conn.prepareCall("{call myproc}");
    cs.execute();How do I get values back from this stage?
    Thank you very much,
    Lior

    The short form answer, which assumes that the stored procedure is returning the XML as an out parameter would go something like this.
         public void build(String newUserID, String newPassword) throws SQLException {
              String sql = "{ call GET_ITEM_DETAIL(?, ?, ?, ?, ?, ?) }" ;
              try{
                   init(newUserID, newPassword) ;
                   setCallableStatement(getConnection().prepareCall(sql)) ;
                   getCallableStatement().setInt(1, getItemNumber()) ;
                   getCallableStatement().registerOutParameter(2, oracle.jdbc.driver.OracleTypes.CURSOR) ;
                   getCallableStatement().registerOutParameter(3, oracle.jdbc.driver.OracleTypes.INTEGER) ;
                   getCallableStatement().registerOutParameter(4, oracle.jdbc.driver.OracleTypes.VARCHAR);
                   getCallableStatement().registerOutParameter(5, oracle.jdbc.driver.OracleTypes.VARCHAR) ;
                   getCallableStatement().registerOutParameter(6, oracle.jdbc.driver.OracleTypes.VARCHAR) ;
                   getCallableStatement().execute() ;
                   setSqlResult(getCallableStatement().getInt(3)) ;
                   setSqlMessage(getCallableStatement().getString(4)) ;
                   if( getSqlResult() != 0 ){
                        throw new SQLException(getSqlMessage(), null, getSqlResult()) ;
                   setResultSet((java.sql.ResultSet) getCallableStatement().getObject(2)) ;
                   if( getResultSet() != null ){
                        while( getResultSet().next() ){
                             setItemType(getResultSet().getString("ITEM_TYPE")) ;
                             setItemValue(getResultSet().getString("ITEM_VAL")) ;
                             setDisplayType(getCallableStatement().getString(5)) ;
                             setDisplaySize(Integer.parseInt(getCallableStatement().getString(6))) ;
              catch(SQLException e){
                   java.util.Date now = new java.util.Date() ;
                   java.text.DateFormat format = java.text.DateFormat.getInstance() ;
                   setSqlMessage( e.getClass().getName() + " : " + format.format(now) + " : " + e.getMessage() + " : IN " + getClass().getName() ) ;
                   System.err.println(getSqlMessage()) ;
                   throw e ;
              finally{
                   closeResources() ;
         }The GET_ITEM_DETAIL stored procedure returns several out parameters of various types. The code registers them as out parameters along with an anticipated type and then calls the getXXX(n) method that corresponds with that data type in the appropriate position.
    As I mentioned in my other post, the onus of returning the XML is on the stored procedure, when you get it into Java it's going to be a java.lang.String that you can then parse by whatever means is appropriate to your situation.
    Regards,

  • How can I get values from listbox?

    Hi all,
    I need to get price values from Price List (Inventory -> Item Master Data screen). It's important to get values from field 'Price' BEFORE item will be added/updated.
    How can I get values from Pricelist listbox?
    Thanks for any suggestions or short sample code.
    Best regards,
    Andy

    Hi Andy
    Here is som sample code that will get the description of the price list and also the price that is displaying at the time. The item master must be open for this snippet of code
      Public Sub GetItemPriceFromOpenWindow()
            'this is assuming item master is open
            Dim oEdit As SAPbouiCOM.EditText
            oEdit = SBO_Application.Forms.GetForm("150", 1).Items.Item("34").Specific
            SBO_Application.MessageBox(oEdit.Value)
            Dim oCmb As SAPbouiCOM.ComboBox
            oCmb = SBO_Application.Forms.GetForm("150", 1).Items.Item("24").Specific
            SBO_Application.MessageBox(oCmb.Selected.Description)
        End Sub
    Hope it helps

  • POPUP FM to get values from a table control?

    I know about the FM POPUP_GET_VALUES to get one or more values from a popup dialog box.  I would like to find a similar FM that allows getting values from a table control or something that allows entry of multiple lines of values.  Is there such a thing, or do I need to write my own?

    it depends on what values you want to enter, better write your own to have a control on the function.

Maybe you are looking for

  • Q: BAPI/FM Attachment list

    Hi all, I'm struggeling for a while with this question and I havn't found a solution yet. Using transaction FBL1N, people of accounting can enter a vendor code and search for Vendor Line Items. By viewing the details of a certain line, they can selec

  • Mx.services.WebService() fails with Can't Find Method in Service

    When I test in debug mode, my webservices fail with can't find method or can't find URL. When I test on the very same webservice with the SWF file embedded in an HTML file, it all works fine! This all worked before I updated to Windows Vista last wee

  • Airport Extreme Card for a Power Mac G5

    Hi! I have a power Mac G5 (1.8 GHZ 512 MB 160 GB) Serial Number XB40**QES. I want to buy an airport extreme card and found here on apple.com that the airport card I need is the M8881LL/A. But everyones at every store I´ve been keep telling me that a

  • Help with a spotty image

    My photo looks fine on CS6, but when my client opens it on his computer (and other computers at his company), the image has white spots all over it. Can you help me figure out what is causing the problem? When I upload the image on my website (www.je

  • Service Request Building Block

    Hello everyone, We are currently evaluating the use of the Service Request for a incident/'alarm" tracking scenario. In this regard, does anyone know if there is a building block configuration guide for this? I was looking in the Best Practices but i