Last element in hashtable?

Is there a way to get the last filled element in a hashtable?

What do you mean with the last one ? The last one added, the one with the highest key (whatever highest mean) )
I do not know how Java implements it's hashmaps, but usually the index is computed from the key, so that the table has empty gaps between filled entries. and the last filled entry is not necesserally the highest by by any sort order nor the last one added. Also any element might not really be an element, but a list of elements that have the same index.
You can get all the keys in form of a set. You can use the set to find out the last of this set or perform any algorithm on it to determine what the last key is.
Regards
SH

Similar Messages

  • How to get the last element of a structure in a textfield in DesignStudio

    Hello,
    how can I get the last element of a structure within a bex query?
    Within the structure we are working with dates that dynamically are buiId (input date - offsets for several months).
    I have to show the last value in a single textfield within DesignStudio.
    Regards
    Frank

    Hi Frank,
    in DS 1.3 you can use forEach function to get the last element of BEx structure (or n-th element in general using if condition)
    var array = DS_CROSSTAB1.getMembers("DHGY5D6XEFO1K45SB00BXFH7A",10);
    var lastMember="";
    array.forEach(function(element, index) {
           lastMember = element.text;
    TEXT_1.setText("Last structure element: "+lastMember);

  • Lots of blank space when printing array with only last element printed

    I have a slight problem I have been trying to figure it out for days but can't see where my problem is, its probably staring me in the face but just can't seem to see it.
    I am trying to print out my 2 dimensional array outdie my try block. Inside the trying block I have two for loops in for the arrays. Within the second for loop I have a while to put token from Stringtokeniser into my 2 arrays. When I print my arrays in this while bit it prints fine however when I print outside the try block it only print the last element and lots of blank space before the element.
    Below is the code, hope you guys can see the problem. Thank you in advance
       import java.io.*;
       import java.net.*;
       import java.lang.*;
       import java.util.*;
       import javax.swing.*;
       public class javaflights4
          public static final String MESSAGE_SEPERATOR  = "#";
          public static final String MESSAGE_SEPERATOR1  = "*";
          public static void main(String[] args) throws IOException
             String data = null;
             File file;
             BufferedReader reader = null;
             file = new File("datafile.txt");
             String flights[] [];
                   //String flightdata[];
             flights = new String[21][7];
             int x = 0;
                   //flightdata = new String[7];
             int y = 0;
             try
                reader = new BufferedReader(new FileReader(file));   
                //data = reader.readLine();   
                while((data = reader.readLine())!= null)   
                   data.trim();
                   StringTokenizer tokenised = new StringTokenizer(data, MESSAGE_SEPERATOR1);
                   for(x = 0; x<=flights.length; x++)
                      for(y = 0; y<=flights.length; y++)
                         while(tokenised.hasMoreTokens())
                            //System.out.println(tokenised.nextToken());
                            flights [x] [y] = tokenised.nextToken();
                            //System.out.print("*"+ flights [x] [y]+"&");
                   System.out.println();
                catch(ArrayIndexOutOfBoundsException e1)
                   System.out.println("error at " + e1);
                catch(Exception e)
                finally
                   try
                      reader.close();
                      catch(Exception e)
             int i = 0;
             int j = 0;
             System.out.print(flights [j]);
    //System.out.println();

    A number of problems.
    First, I bet you see a lot of "error at" messages, don't you? You create a 21x7 array, then go through the first array up to 21, going through the second one all the way to 21 as well.
    your second for loop should go to flights[x].length, not flights.length. That will eliminate the need for ArrayIndexOutOfBounds checking, which should have been an indication that you were doing something wrong.
    Second, when you get to flights[0][0] (the very first iteration of the inner loop) you are taking every element from the StringTokenizer and setting flights[0][0] to each, thereby overwriting the previous one. There will be nothing in the StringTokenizer left for any of the other (21x7)-1=146 array elements. At the end of all the loops, the very first element in the array (flights[0][0]) should contain the last token in the file.
    At the end, you only print the first element (i=0, j=0, println(flight[ i][j])) which explains why you see the last element from the file.
    I'm assuming you have a file with 21 lines, each of which has 7 items on the line. Here is some pseudo-code to help you out:
    count the lines
    reset the file
    create a 2d array with the first dimension set to the number of lines.
    int i = 0;
    while (read a line) {
      Tokenize the line;
      count the tokens;
      create an array whose size is the number of tokens;
      stuff the tokens into the array;
      set flights[i++] to this array;
    }

  • How to delete the last element of a collection without iterating it?

    how to delete the last element of a collection without iterating it?

    To add to jverd's reply, even if you could determine the last element, in some collections it is not guaranteed to always be the same.
    From HashSet:
    It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.

  • How to select the last elements in a string

    Hi Guys
    I am using UART RS232 protocol and i need to calculate the check sum. My data came in decimal and in the end it must be doubles to manipulate it. So my problem is, for example, the sum of all elemants is in decimal 1742 and in hex is 6CE and i wont only the last two elemants, CE that corresponds to 206 that is the result of my checksum. Can anyone help me? 
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    String last elements.vi ‏9 KB

    Thanks Syrpimp
    My data came from HMI in decimal like the example that i show above. Each cell is a value. You used an array, but i think that i can't use it because it must be done automatically and the data field have variable length. 
    The UART protocol frame has a start frame field that corresponds to two ‘{‘ characters and an end frame field that corresponds to two ‘}’. Additionally, besides the data field, that has variable length, it has a byte that corresponds to the command type and another that is the checksum. The following table illustrates the protocol.
    Bytes considered in checksum
    Command Data
    Start Frame
    Cmd
    (hex)
    Data0
    Data1
    Data2
    Data3
    Data4
    Data5
    Data6
    Data…
    CHK SUM
    End Frame
    1 Byte CHK SUM (sum of all data bytes truncated to 1 byte)
    Fig. 1 UART communication protocol template
    I receive data like this:
    123
    123
    160
    54
    111
    103
    110
    108
    107
    109
    108
    108
    100
    100
    100
    100
    0
    0
    1
    4
    5
    0
    0
    0
    0
    0
    0
    7
    96
    1
    0
    0
    0
    0
    0
    10
    51
    1
    0
    0
    51
    1
    1
    23
    12
    0
    206
    125
    125
    I'm trying explain my doubt the best way i can and i thank you all.

  • Last element in string

    Hello all
    I am having a string like this:
    55.000000; 10.000000; 0.100000; 1.000000; 1.000000; 0.100000; 0.000000; 0.000000; 1.000000; 1.000000; 22.000000; 0.100000; 6144.000000;
    The length of the string is not always same. What i want is to have the last element. i.e in this case  6144
    One way is to get the string length and using string subset to get the last element. But for this, the length must be always constant.
    Is there any other way to get the last element independant of the string length
    thanks
    Nghtcwrlr
    ********************Kudos are alwayzz Welcome !! ******************
    Solved!
    Go to Solution.

    Since you have the extra semicolon at the end, I actually grabbed the second-to-last element of the array after the spreadsheet string to array.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Get last element.png ‏13 KB

  • How to remove only the last element of spreadsheet string

    I use path to string option to store image path into database and while retrieving the string is again converted into path but it gives out an error as the output of array to spreadsheet string gives out a tab at the end which is unable for the IMAQ read file to recognise.but when i use the path of the image directly into IMAQ readfile the image is opened . so how to remove the tab only at the end of output of the spreadsheet string(whose length can vary)? I have also attached my program with this.
    Attachments:
    retrieve_images_from_DB.vi ‏65 KB
    file_path_to_db_(images).vi ‏40 KB
    create_table_for_images.vi ‏45 KB

    indhu wrote:
    > Thanks for your reply!
    > But my problem is to remove only the last element(which is a tab or an
    > alphabet) from a spreadsheet string of any length.
    If you just want to remove the last character of a string just use the
    String Size function reduce the result by one and wire it together with
    the string to the Split String function.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • JComboBox shows "Java Applet Window" as last element

    Hey all,
    I am having a problem with using JComboBox. When I use JComboBox and show it in a JDialog (popup window), the last element of the drop down (JComboBox) is "Java Applet Window". This element is, however, not selectable. I want to get rid fo the "Java Applet Window" in my dropdown.
    This problem only happens when my applet opens up a JDialog that has the JComboBox, but does not happen when I add the JComboBox directly to the applet.
    I've read around in other forums that this has to do with security. I understand the need to show that a popup window (JDialog) is an applet window so the user doesn't mistake it as one of the native windows. But, the JComboBox is not a whole 'nother window, so why does it feel the needs to add that last line to designate it as a "Java Applet Window?"
    Thanks.
    Nina.

    My apologies, I did not clarify myself in my question. Sorry that I created misunderstandings of the problem - as evident in the response in the previous post from himanshug.
    I am using JDK 1.3.1
    I must use an applet, but all my components are standalone. They can be ran as a standalone application. But for deployment, we are using applets. It's easier to do applets so clients can access via browser than deploy a whole application installation on 50 machines halfway across the world.
    And no, there is no element in my list that says "Java Applet Window". When running my application standalone, the "Java Applet Window" does not appear as the last element in my drop down.
    The "Java Applet Window" also does NOT appear when I add the drop down directly to the applet. It only appears when the drop down is in a JDialog that gets launched by an applet.
    My problem: How to get rid of the "Java Applet Window" as it seems something is adding this to my dropdown. And it's not my code that is adding it.
    Thanks. I am also up'ing the duke dollars for a solution to this to 15.

  • How to display last element in a dynamic 1d array

    hi..
    i want to display the value of last element in a 1d dynamic array.../ i mean ..if i stop the vi run, i need to display the last element in the array..how can i do this?
    and is there any way to use a button to start the vi...instead of using the Run button on the vi front panel??
    Solved!
    Go to Solution.

    Index array!.  Use array size to determine the size of your array, subtract 1, feed that in the index terminal of Index Array.
    You have to start the VI running somehow.  It could be set to run when opened.  Assuming what you want is a means to type values into a front panel, hit a GO button that you created on the front panel, then have the real part of the VI execute.  You could use an event structure.  Or put a while loop at the beginning with a small wait statement in side that basically just polls the GO button.  When that button is pressed, the true boolean stops the while loop and allows the program to proceed to the main body of your program.

  • Last element in structure

    hey all-
    i am trying to add a comma if this is last element in
    structure:
    <cfset stuff=structnew()>
    <cfset stuff.first=1>
    <cfset stuff.first_first=2>
    <cfset stuff.first_first_first=3>
    <cfset stuff.first_first_first_first=4>
    <cfset stuff.first_first_first_first_first=5>
    <cfdump var="#stuff#">
    <cfoutput>
    <cfloop collection="#stuff#" item="i">
    '#stuff
    #'<cfif StructCount(stuff) lt 6>,</cfif>
    </cfloop>
    </cfoutput>
    but it is not workin. how do i get the last
    element.

    As Adam said structures are unordered and there is no concept
    of last.
    But it looks like you are trying to output a list of elements
    by looping
    over the structure and do not want a comma after the last
    element. Your
    if logic is the problem here, it will always be true.
    <cfoutput>
    <cfloop collection="#stuff#" item="i">
    '#stuff
    #'<cfif StructCount(stuff) lt 6>,</cfif>
    </cfloop>
    </cfoutput>
    StructCount(stuff) is always five. It the size of the
    structure is not
    going to change while you are looping over it. You need a
    counter and
    then compare that counter to the size of the structure to
    know you have
    reached the end of it.
    <cfoutput>
    <cfset counter = 0>
    <cfloop collection="#stuff#" item="i">
    <cfset counter = counter + 1>
    '#stuff#'<cfif counter lt
    StructCount(stuff)>,</cfif>
    </cfloop>
    </cfoutput>
    This could be simplified with a list function.
    <cfset stuffList = ''>
    <cfloop collection="#stuff#" item="i">
    <cfset stuffList = listAppend(stuffList,stuff
    )>
    </cfloop>
    <cfoutput>#stuffList#</cfoutput>

  • React on Array's last Element arrival

    Hello NI developers!
    My VI reads data from board and fills array. As data acquisition speed is slower than VI performance I want VI react and perform action exactly when array gets it's last element. I don't want to use Stacked Sequence Structure, because there NEXT frame executes only when it gets all the data from previous frame and if I manipulate large amounts of data (i.e. Megabytes) it will be hanging somewhere in memory. I want to catch that moment when array filled with last element. Any advices how can I reach that?
    Thank you in advance.
    Message Edited by ACiDuser on 06-26-2008 08:17 AM

    I want calculate transfer speed. CIN measures time that takes FOR Loop and sends it to LV. And I get this time with microsecond precision. I got an idea... Maybe I should use this Stacked Event Structure only for "Time" indicator.. and inside Check If it's not equal with 0 then - calculate speed!

  • Last element of DefaultStyledDocument has \n appended, why?

    Hello!
    I have some trouble getting the text of styledDocument in JTextPane. I get the text recursively by traversing the Elements and convert that to xml and save it. I do not understand why I get \n as last leaf-Element. There is no \n when I call getText in Document or JTextPane. So with every saving and loading the document gets longer and longer because there is \n appended every time.
    Here is a small program that shows the problem:
    import javax.swing.*;
    import javax.swing.text.*;
    public class TextPaneWriter extends JFrame {
         public TextPaneWriter() {
              DefaultStyledDocument doc = new DefaultStyledDocument();
              try {
                   SimpleAttributeSet a = new SimpleAttributeSet();
                   StyleConstants.setBold(a, true);
                   doc.insertString(doc.getLength(),
                             "I wish I was in Carrickfergus\n", a);
                   a = new SimpleAttributeSet();
                   StyleConstants.setItalic(a, true);
                   doc.insertString(doc.getLength(),
                             "Only for nights in Ballygrant\n", a);
                   a = new SimpleAttributeSet();
                   StyleConstants.setUnderline(a, true);
                   doc.insertString(doc.getLength(),
                             "I would swim over the deepest ocean,\n", a);
                   a = new SimpleAttributeSet();
                   StyleConstants.setBold(a, true);
                   doc.insertString(doc.getLength(),
                             "For my love to find", a);
              catch (BadLocationException x) {
              JTextPane tp = new JTextPane(doc);
              this.getContentPane().add(tp);
              System.out.println("Get text of JTextPane:");
              System.out.println(tp.getText() + "END");
              System.out.println();
              System.out.println("Get text of Document:");
              try {
                   System.out.println(doc.getText(0, doc.getLength()) + "END");
              catch (BadLocationException x) {
              System.out.println();
              System.out.println("Get text recursively:");
              this.writeDocRec(doc.getDefaultRootElement(), doc);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setSize(200,200);
              this.setVisible(true);
         private String getTextOfElement(Element styledElement,
                   DefaultStyledDocument doc) {
              String text = "";
              int startOffset = styledElement.getStartOffset();
              int endOffset = styledElement.getEndOffset();
              try {
                   text = doc.getText(startOffset, endOffset-startOffset);
              catch (BadLocationException x) {
                   x.printStackTrace();
              return text;
         private void writeDocRec(javax.swing.text.Element element,
                   DefaultStyledDocument doc) {
              if (element.isLeaf()) return;
              for (int i=0; i<element.getElementCount(); i++) {
                   javax.swing.text.Element child = element.getElement(i);
                                  if (child.isLeaf()) {
                        System.out.print(this.getTextOfElement(child, doc) + "END OF ELEMENT\n");
                   writeDocRec(child, doc);
          * @param args
         public static void main(String[] args) {
              new TextPaneWriter();
    }And this is what I am getting:
    Get text of JTextPane:
    I wish I was in Carrickfergus
    Only for nights in Ballygrant
    I would swim over the deepest ocean,
    For my love to findEND
    Get text of Document:
    I wish I was in Carrickfergus
    Only for nights in Ballygrant
    I would swim over the deepest ocean,
    For my love to findEND
    Get text recursively:
    I wish I was in Carrickfergus
    END OF ELEMENT
    Only for nights in Ballygrant
    END OF ELEMENT
    I would swim over the deepest ocean,
    END OF ELEMENT
    For my love to findEND OF ELEMENT
    END OF ELEMENT
    So why is there another element with \n?
    I can only think of digging in the xml-document after parsing finding the last element and removing the last \n. Or is it \n\r or \r\n?!?!? It does not feel good to do something like that........
    Thank you!
    Annette
    Message was edited by:
    Annette

    Sometimes a bit of sleep is better than any thinking!
    I had an idea this morning and it seams to be working. I change the recursive method to:
         private void writeDocRec(javax.swing.text.Element element,
                   DefaultStyledDocument doc) {
              if (element.isLeaf()) return;
              for (int i=0; i<element.getElementCount(); i++) {
                   javax.swing.text.Element child = element.getElement(i);
                   if (child.isLeaf()) {
                        int start = child.getStartOffset();
                        int end = child.getEndOffset();
                        int len = doc.getLength();
                        if (end > len) System.out.println("len " + len
                                  + " start " + start + " end " + end);
                        else System.out.print(this.getTextOfElement(child, doc)
                                  + "END OF ELEMENT\n");
                   writeDocRec(child, doc);
         }I found that the last element, that I do NOT want and that contains that \n has endIndex > doc.getLength(). So if I find an element that satisfies this condition I know it is the last, not wanted element, and skip it. Does it make any sense to have an element with index > length?
    Do you think that this is a good solution? Or is it some kind of trial and error and not really understanding what is going on?
    I would appreciate some advices. Thank you!
    Annette

  • Stopping while loop after last element of 2d array is passed through

    I posted something similar to this before, but what I got didn't work.  So this time I'll try to be more clear with what I am trying to do.  What I have done is combine two 1d arrays into a 2d array, and am using it to run an experiment.  I split the 2d array into a 1d array by column, and am trying to get the while loop that the array is in to stop after  the last element of the array is indexed.  I need to use a while loop because the array is constantly updating because the number of elements can be changed while the program is running.  What I am having trouble with is getting the while loop to stop after the last element has run, because the last element is subject to change.  Any ideas?
    Thanks 

    I am trying to run a measurement using labview to control different instruments.  The program is suppossed tp work in that it runs a measurement for each current setpoint inputed, for 1 magnetic field setpoint.  So for example, if the magnetic field setpoint is 8000 gauss, and the two current setpoints are .00001 amp, and .0001 amp, it will run the meauserement twice for the 2 current setpoints for each magnetic field setpoint.  What I am trying to do is that sometimes, I might have to edit the magnetic field setpoints while the program is running.  I am having trouble with refreshing the magnetic field setpoints, which allows the user to input a new magnetic field setpoint while it is running.

  • Retrieve Last element from Collection

    Hi,
    I am a beginner in Java. Can somebody tell me how to retrieve last element from java.util.collection without Iterating?

    Hi,
    I am a beginner in Java. Can somebody tell me
    how to retrieve last element from
    java.util.collection without Iterating?You realize of course that this is rather silly since not every Collection necessarily has a "last" element. For it to have the notion of a "last" element it would have be ordered and would be a List.

  • How to find the last element of a byte array

    Dear all,
    I have a byte array with a max lenght of 1024*50 bytes. In that array I store the bytes read from a file. How can I find where the array ends (i.e. which is the last valid element of the byte array)?
    Thank you for your help.
    Best Regards,
    JIM

    I want to send files over TCP connection using BufferedOutputStreams and BufferedInputStreams. The first side (e.g. the client) sends a file (e.g mp3 file or jpeg image) to the server using the code
      public void sendFile(Socket s, String FileName) throws Exception
              BufferedOutputStream out = new BufferedOutputStream(s.getOutputStream());  
              BufferedInputStream in = new BufferedInputStream(new FileInputStream(FileName));
              int len = 0;
              while ( (len = in.read(buffer)) > 0) {
                out.write(buffer, 0, len);
              in.close();
              out.flush();
            }(The client does not close the BufferedOutputStream out because other files will be sent afterwards)
    Then, the server receives the file using the code:
            public void receiveFile(Socket s, String FileName) throws Exception
              OutputStream out = new BufferedOutputStream(new FileOutputStream(FileName)); 
              InputStream in = new BufferedInputStream(s.getInputStream());
              int len = 0;
              while ( (len = in.read(buffer)) > 0) {
                out.write(buffer, 0, len);
                break;
              out.flush();
              out.close();
            }(likewise the InputStream in is not closed for the same reasons).
    In order the server to receive the file and stop reading the BufferedInputStream, I will have to make some modifications to this part of the code,
    while ( (len = in.read(buffer)) > 0)so as to know when the whole file has been received.
    Thus, even if I send the length of each file, I will not be able to read it. Could you please recommend me a solution?

Maybe you are looking for