Using keys to search and retrieve values from HashMap

I've been fiddling around with this problem for a while and can't seem to find any working solution. What I have is a method that I want to return all values from a HashMap, but instead of using the regular keys for a HashMap (0, 1, 2, 3), my keys are different numbers such as 51414, 62513, etc.
public Car[] getAllCars() {
          Map<Integer, Car> myCars = system.getCars(); //getCars() returns HashMap of Car objects from another class
          Car[] c = new Car[myCars.size()];
          if(myCars.size()!=0) // ensure map is populated
               for(int i=0; i<myCars.size(); i++)
                    myCars.get(i);
          return c;    
     }So what's happening at the moment is it loops through myCars and gets some values, but only those ones at the keys of 0-15 (the size of the Map). What I need is to get the Keys from myCars and use them to return all Car objects. The HashMap API has something called KeySet() which I think could help me, but I can't get that working.
Any ideas?

DiscoInferno wrote:
Short of an SSCCE I think this might more accurately describe what I'm after.
public Car[] getAllCars() {
          Map<Integer, Car> myCars = system.getCars();  //getCars() returns HashMap of Car objects from another class
          Car[] c = new Car[myCars.size()];
          Set<Integer> s = holds.keySet();
          Iterator keyIter = s.iterator();
          if(myCars.size()!=0)
               while (keyIter.hasNext()) {
                    Object key = keyIter.next();
                    Car cc = myCars.get(key);
                    System.out.println(myCars.get(key));
          return null;
     }What that does is gets the Car object that matches the specified key. What I need is for it to be returnable as an array of Car objects. I don't want it to print, but the output that is printed is basically what I want to be returned to an array.First, I'm not sure how you managed to find keySet() and not find values().
Second, okay, so you know how to get each value. Do you not know how to set a value in an array? Do you not know how to return a value from a method? Google can help you find tutorials for those. Otherwise, I have no idea what difficulty you're having.

Similar Messages

  • Get , store and retrieve values from JComboBox, JT.......

    please can you show me how to collect informations from some JComponents like JComboBox, JList , JTextField, JTextArea etc and store them on clicking on a single button and also retreiving them by clicking on another single button

    below are some functions that u can use:
    JComboBox: getSelectedItem()
    JList: getSelectedValue()
    JTextField, JTextArea: getText()
    basically u need to have button, add an action listener for the button, and store the value using the above functions when the button is clicked.
    hth.

  • 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

  • How can i remove a key and its value from properties file

    hi all,
    i want remove a particular key and associated value from the
    properties file. is their any standard way of doing?
    thanks inadvance
    daya

    hi,
    thanks
    i am able to remove the key,
    one more question how can avoid storing date and time
    in properties file.
    thanks
    daya

  • Difference in WS performance between Search and Retrieve operations?

    All,
    We are currently working on a new repository and planning to use MDM webservices on top of that repository for searching and retrieving the data.
    Now I'm curious about the difference in performance between the Search and the Retrieve operations and also within the Retrieve operation, between the different identification methods (internal ID, auto ID, remote key, unique field and display field).
    Because in the webservices guide is stated that the identification methods are listed in order of best performance, but what are these performance differences between these methods (e.g. a retrieve on internal ID is x times faster than a retrieve on remote key which on his turn is x times faster than a retrieve on display fields which on his turn is x times faster than a search operation on same display field).
    Of course the performance depends on lot of other things as well, but I just want to get a feeling on the performance related to eachother (keeping all other variables that can influence the performance the same!)!
    I hope that any of you has experiences with all possibilities and can share performance measurements between the different operations related to eachother.  Thanks in advance.
    Regards,
    Marcel Herber

    Hi,
    Did you implment Webservices in your site.
    We are also having a similar scenarion where we have to serach a Records in MDM from SAP PI based on the certain criteria. I am concerned about the SAP MDM performance , since we are having heavy amount data being loaded every 30 minutes.
    Please let me know the performace aspects of using Webservices.
    Thanks
    Ganesh Kotti

  • Retrieve values from a HTML table !!!

    Hi.
    How can i retrieve values from a HTML table using javascript ?
    I´m trying to use the command "document.getElementsByTagName" without success.
    Thanks in advance.
    Eduardo

    Hi, Deepu.
    I´m still with trouble in retrieving the value in HTML.
    In debug the C_CELL_ID seems to be correctly updated but
    when using the command "document.getElementById" the value is always "null".
    I implemented in the method DATA_CELL the code :
      if i_x = 3 and i_y = 2.
      C_CELL_ID             = 'zs'.
      C_CELL_CONTENT = 10. 
      endif.
    And in HTML :
    var ztest = document.getElementById('zs');
    alert(ztest);
    Could you help me please.
    Many regards
    Eduardo S.
    Message was edited by: Eduardo   Silberberg

  • Retrieving values from Database in Excel Task Pane App

    So far,
    I created a website with a database on Azure, I then published my App to Azure. My problem is that I'm not sure how I retrieve values from the database (in SQL: SELECT * FROM EXAMPLE_TABLE WHERE date = str). If someone could provide me with sample code,
    that would be amazing! :D
    It would also be very helpful if anyone knew a method to automatically update the database using information from a xml stream on another website, once a day.
    Thank you!

    Hi,
    >> My problem is that I'm not sure how I retrieve values from the database
    You can use jquery ajax call to call your webserivce or REST API, which will query the database and return a json result.
    Sample:
    Apps for Office: Create a web service using the ASP.NET Web API
    >> It would also be very helpful if anyone knew a method to automatically update the database using information from a xml stream on another website
    For the database sync-up question, I suggest you posting them on the forums like SQL Server Forum.
    Thanks for your understanding.
    Best Regards
    Lan
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Retrieving values from a table

    Hi all,
    I need to retrieve values from CSKS-KOSTL for values containing the pattern entered by the user. For example, if the user enters 1, need to retrieve all the KOSTL values starting with 1. But when i write a SELECT statement mentioning where kostl in '1', it is ignoring all the values like (0000001, 00001034, 0012334, and others). Only values starting with 1 is only retrieved as this is a character field and due to conversion routine, zeroes are prefixed while storing in the database.
    Could any one let me know how to retrieve the values from the database in this situation?

    If you want to use IN operator in your where clause then you should define a range variable(R_KOSTL) which refers to CSKS=KOSTL and populate the range as below
    R_KOSTL-SIGN = 'I'.
    R_KOSTL-OPTION = 'CP'.
    R_KOSTL-LOW = '1*'.
    APPEND R_KOSTL.
    and then write your select statement as .... WHERE kostl IN r_kostl.
    The approach suggested by Amit should also work fine.
    Thanks
    Kiran

  • How to retrieve value from xml file

    hi all,
    can somebody pls tell me how to retrieve value from xml file using SAXParser.
    I want to retrieve value of only one tag and have to perform some validation with that value.
    it's urgent .
    pls help me out
    thnx in adv.
    ritu

    hi shanu,
    the pbm is solved, now i m able to access XXX no. in action class & i m able to validate it. The only thing which i want to know is it ok to declare static ArrayList as i have done in this code. i mean will it affect the performance or functionality of the system.
    pls have a look at the following code snippet.
    public class XMLValidator {
    static ArrayList strXXX = new ArrayList();
    public void validate(){
    factory.setValidating(true);
    parser = factory.newSAXParser();
    //all factory code is here only
    parser.parse(xmlURI, new XMLErrorHandler());     
    public void setXXX(String pstrXXX){          
    strUpn.add(pstrXXX);
    public ArrayList getXXX(){
    return strXXX;
    class XMLErrorHandler extends DefaultHandler {
    String tagName = "";
    String tagValue = "";
    String applicationRefNo = "";
    String XXXValue ="";
    String XXXNo = "";          
    XMLValidator objXmlValidator = new XMLValidator();
    public void startElement(String uri, String name, String qName, Attributes atts) {
    tagName = qName;
    public void characters(char ch[], int start, int length) {
    if ("Reference".equals(tagName)) {
    tagValue = new String(ch, start, length).trim();
    if (tagValue.length() > 0) {
    RefNo = new String(ch, start, length);
    if ("XXX".equals(tagName)) {
    XXXValue = new String(ch, start, length).trim();
    if (XXXValue.length() > 0) {
    XXXNo = new String(ch, start, length);
    public void endElement(String uri, String localName, String qName) throws SAXException {                    
    if(qName.equalsIgnoreCase("XXX")) {     
    objXmlValidator.setXXX(XXXNo);
    thnx & Regards,
    ritu

  • Recording measured voltage and current values from LCR 4284A

    Hello,
    I want to use the labview VI to record the measured voltage and current values from LCR 4284A. These are shown as Vm and Im on the instrument screen. Is it possible to record these values using a VI?
    I have looked through the drivers that are available through the "Instrument driver network" (Link) for 4284A but none of the VIs give any option to monitor Vm and Im. If you know how this can be done then I would really appreciate a reply.
    Thanks
    Mansoor

    I haven't used the instrument but there are functions to enable/read voltage level and current level monitors. Are those different than what you are asking for? What does the manual say about Vm and Im and programatically getting them? If you can find the command in the manual, you can just open the VI Tree and do a text search for the command.

  • WPF- How to save and retrieve details from database

    I want to develop an desktop app to save and retrieve details from database, but am having a little hitch
    am getting errors in my code, kindly advice below are the required code
    xaml
    <Grid>
            <TextBox HorizontalAlignment="Left" Height="23" Margin="144,28,0,0" TextWrapping="Wrap" x:Name="TbxId" VerticalAlignment="Top" Width="193"/>
            <TextBox HorizontalAlignment="Left" Height="23" Margin="144,134,0,0" TextWrapping="Wrap" x:Name="TbxFn" VerticalAlignment="Top" Width="193"/>
            <TextBox HorizontalAlignment="Left" Height="23" Margin="144,77,0,0" TextWrapping="Wrap" x:Name="TbxLn" VerticalAlignment="Top" Width="193"/>
            <Label Content="Student ID" HorizontalAlignment="Left" Margin="10,28,0,0" VerticalAlignment="Top" Width="101"/>
            <Label Content="Last Name" HorizontalAlignment="Left" Margin="10,134,0,0" VerticalAlignment="Top" Width="101"/>
            <Label Content="First Name" HorizontalAlignment="Left" Margin="10,77,0,0" VerticalAlignment="Top" Width="101"/>
            <Button x:Name="BtnSave" Content="Save" HorizontalAlignment="Left" Margin="23,206,0,0" VerticalAlignment="Top" Width="75" />
            <Button x:Name="BtnBrowse" Content="Browse" HorizontalAlignment="Left" Margin="149,206,0,0" VerticalAlignment="Top" Width="75" Click="Save"/>
            <Button x:Name="BtnShow" Content="Show" HorizontalAlignment="Left" Margin="294,206,0,0" VerticalAlignment="Top" Width="75"/>
            <WindowsFormsHost Grid.Column="0" Margin="448,28,75,243">
                <wf:PictureBox x:Name="pictureBox1" Height="150" Width="150" SizeMode="StretchImage"/>
            </WindowsFormsHost>
        </Grid>
    cs
    private void Browse(object sender, RoutedEventArgs e)
                SqlConnection cn = SqlConnection(global::DatabaseApp.Properties.Settings.Default.Database1ConnectionString);
                try
                    OpenFileDialog dlg = new OpenFileDialog();
                    dlg.Filter = "JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|All Files(*.*)|*.*";
                    dlg.Title = "Select Student Picture";
                    if (dlg.ShowDialog() == DialogResult.OK)
                        imgLoc = dlg.FileName.ToString();
                        picStu.ImageLocation = imgLoc;
                catch(Exception ex)
                    System.Windows.MessageBox.Show(ex.Message);
    Thank you
    Jayjay john

    Hi Joakins,
    I think Lloyd has a point here in that all I see there which is really database related is a connection string.
    Maybe your question is more general though and you're just asking how to work with a database as a general principle.
    Personally, I like entity framework and would recommend that.
    You can read a shed load of stuff about it.
    https://msdn.microsoft.com/en-gb/data/ef.aspx?f=255&MSPPError=-2147217396
    With WPF almost every dev uses MVVM and I'm no exception.
    You may find this interesting:
    http://social.technet.microsoft.com/wiki/contents/articles/28209.wpf-entity-framework-mvvm-walk-through-1.aspx
    The article for the second in the series is only partly written, but the sample is complete:
    https://gallery.technet.microsoft.com/WPF-Entity-Framework-MVVM-78cdc204
    Hope that helps.
    Recent Technet articles: Property List Editing;
    Dynamic XAML

  • I want to store and retrieve images from a oracle datrabase's BLOB type

    Hi all
    I am using WebLogic and Oracle 10g.I have to store images and retrieve them from a BLOB type.
    Please help .

    Please have a look to the Database Application Developer's Guide - Large Objects
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14249/toc.htm

  • I have a windows 7 desktop with an external hard drive setup on my home network, will i be able to access this on my home network to save and retrieve files from my mac air?

    i have a windows 7 desktop with an external hard drive setup on my home network, will i be able to access this on my home network to save and retrieve files from my mac air?

    Troubleshooting Home Sharing - http://support.apple.com/kb/TS2972

  • Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Facebook like button is not working, I have used the muse widget and created code from facebook. Does anyone know how to get this to work?

    Hi connally25,
    Below is a link to a video tutorial on how to add a Facebook Log button, please check if you have followed the same steps to add the video.
    http://tv.adobe.com/watch/learn-adobe-muse-cc/adding-a-facebook-like-button/
    If you have followed the steps correctly and the button still does not work; here is a link to a forum thread which might help solving the issue:
    Facebook Follow Widget not working
    Regards
    Sonam

  • There was a button/plug in that alloyou to search and dowmload MP3 from the tool bar it is no longer there how can I find it?

    There was a button/plug in that alloyou to search and dowmload MP3 from the tool bar it is no longer there how can I find it?

    The add-on you are looking for may no longer be available.
    Do you remember its name?
    Go to the '''[https://addons.mozilla.org/en-US/firefox/ Mozilla Add-ons Web Page]''' {web link}
    (There’s a lot of good stuff here) and search for what you want.

Maybe you are looking for