Java arrays - can you name the keys?

i have 1 function that declares 2 ArrayLists of type String. They are the same size and the values are related. Let's call them A & B.
I was hoping i could have my function return just 1 array, with the values of arraylist A being they keys of the returned array, and the values of arraylist B being the values in the returned array.
But can you name the elements of an array in java? in php you can, but in java, the only examples i have seen only use the standard #'s: 0, 1, 2, 3, etc. if you can, please post sample syntax.
i guess i could use a double scripted array, but... well i don't exactly know what the sytax would be for that in declaring the funciton.
if someone has a link of these kinds of examples / topics they could send me - that would be great too - i googled it but haven't really come across any.
thanks in advance

It appears as though what you are trying to do is associate a specific "key" value with another value. For example, let's say you want the word "dog" to be the key for the arraylist value of "bull dog."
The perfect data structure for this that Java provides is called a Map. Here is some sample code.
//create something called a HashMap where the first
//value is the key, and the second value is the value
//that the key is associated with
HashMap<String, String> map = new HashMap<String, String>();
//now, consider the previous example...
//here is the syntax for storing those values
map.put("dog", "bull dog");
//and this would be the syntax for getting a value
String value = map.get('dog");
//which would give "bull dog"
{code}
Hope that helps :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Is there anyway to organize icloud photo steams into abc order? and can you change the key photo image??? makes me crazy!

    I am searching for ways to organize my photo streams...alphabetical preferably.
    Also how do you change the key photo from something random that i did not choose to be the key photo (in the photo stream/icloud mode).
    Thank you!
    sue

    As far as I can see, sue, the shared Photo Streams will always show the photo last added as the key photo. So just make sure the last photo you add is a photo like to see as the key photo. I do no know of any method to arrange the photo streams alphabetically. My photo streams are neither shown in chronological order nor in the order I created them.

  • Can you move the keys about on a 2010 MBA, 11"?

    Hi,
    A friend has called me from his European holiday to say he can get me a new MBA for what works out to just over £500, about 1/3 off the UK RRP! The only problem is the keyboard would be AZERTY, not QWERTY.
    Is it possible to pop the keycaps off and swpa them about to 'make' a QWERTY keyboard on the new MBAs?
    Thanks,

    No offense but the above poster is 100% wrong. The key caps on the MacBook Air are totally removable and switchable; I just pulled off a couple of mine and swapped them around.
    There are plenty of tutorials on YouTube on how to do it, though the ones I saw involved popping off the underlying scissor mechanism, which is overkill imho. Just lift up the bottom right corner of the key you need to swap out with a fingernail or a small jeweler's screwdriver and then pull delicately up. To reinsert a key, just slide the key in towards the monitor and push down.
    You do have to be very, very careful, though, as the plastic parts underneath are very delicate. Once you've switched the keys around once, I wouldn't do it again. If you do break one of the scissor mechanisms, though, you might be able to swing by a local Apple store and get a replacement for free.

  • J2ME: can you clear the key pressed buffer on a cell?

    I am having trouble with keypressed.
    I am writing a cell phone game in MIDP 2.0. Basically its the standard GameCanvas setup, where you have a main game loop and it calls your input function. The input function then does:
    int keyStates = getKeyStates();
    keyprocessing
    to get the states.
    When I demo it on the color phone in WTK2.0, and tap the right arrow, and my input loop processes the right multiple times. My initial thought was that the loop ran too fast perhaps and it read the press several times, so I put in a delay before keyprocessing:
    int keyStates = getKeyStates();
    long time = System.currentTimeMillis();
    if ((time - timeOfLastInput) < MIN_TIME_INPUT)
    return;
    keyprocessing
    timeOfLastInput = System.currentTimeMillis();
    Now, I have cut it down to only going in a direction once. However, if I press up, down, left, right, (in honor of Konami) My input goes as follow Up (delays MIN_TIME_INPUT) then Down, delays again, left, delays, right.
    And so I am out of ideas.

    haha, this is interesting... a month ago, i had the same problem, until i flash of intellect put me out of my misery...
    rule 1: dont use the time delay. with the processor speed of the cell phones, with your delay, it will take a decade before the app runs...
    heres how to do the coding to keep it to only 1 step at a time: ( i do it in the run method of the thread)
    int originalKey = 0; // keeps the keystates once the execution completes once
    int key = 0; // keeps the keystates for comparision
    while(isRunning) {
        key = getKeyStates();
        if(key == originalKey) {
            originalKey = 0;
            continue;
        if( (key & LEFT_PRESSED) != 0) {
            // do what you want to do, or who you want to do
            originalKey = key;
    // do the same for right pressed and etc etc... this will keep your code from executing too many timesheheh... i think i deserve a few dukes...

  • When you have 1 itunes library.. and 2 ipods.. different names.. how can you share the same library???

    When you have 1 itunes library.. and 2 ipods.. different names.. how can you share the same library???  All of the songs that were put on there from a CD will sync, but the songs that were purchased.. "cannot be found"   How can we merge them?? or how can we share all songs.. purchased or not!

    When you have 1 itunes library.. and 2 ipods.. different names.. how can you share the same library???  All of the songs that were put on there from a CD will sync, but the songs that were purchased.. "cannot be found"   How can we merge them?? or how can we share all songs.. purchased or not!

  • Can you change the field names in the address book?

    Can you change the Pager field name to read 2nd cell?

    No.
    This add-on https://freeshell.de//~kaosmos/morecols-en.html allows you to modify the labels of the 4 custom fields of the contact card

  • Can you get the file name of the current executing TSQL script?

    Can you get the file name of the current executing TSQL script? I wrote entries to a generic log file and would like to include the script name.

    Okay, So What you can do is
    1. Read get the version from your  database and redirect it to a text file(SQLCMD outout can be directed to text file using -o option or windows redirection operator >)
    2. Now you can read this value from the text file either inside a batch file or a powershell script and decide what operations you can do. 
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • On Yahoo Mail...and ONLY Yahoo Mail..I get a 404 error after entering my user name and password. This doesn't happen with IE, just Firefox, and just Yahoo Mail. Yahoo was absouletly no help whatsoever; can you solve the mystery? Thanks

    On Yahoo Mail...and ONLY Yahoo Mail..I get a 404 error after entering my user name and password. This doesn't happen with IE, just Firefox, and just Yahoo Mail. I tried uninstalling and reinstalling FF; no change. Yahoo was absolutely no help whatsoever; can you solve the mystery? Thanks

    HI Emmet,
    thanks so much for your posts back. I really appreciate it and yes that does help to know that you could not get it working.
    I did have some success, in removing the SSL Authentication checkbox in the smtp server settings - I found that this allowed my friend to be able to send mail from the mail app via his sbcglobal (yahoo) account.
    So that did help but of course the messages do not have ssl encryption and I'm not sure how big a deal that is for an individual. He is able to receive mail but unless the SSL authentication box is unchecked, he cannot send.
    i hope that helps anyone out there also!
    Thanks also for the tip about sparrow - yes I have heard of it and it is very popular, he may end up using that in the end.    
    Thanks again, much appreciated.
    Felix    

  • My configuration audio "output" is only numerique and I would like listen to audio by integrated loudspeaker. I can't use the keys "sound on my computer. If I click on I have a icon "forbiden".  Can you help me

    my configuration audio "output" is only numerique and I would like listen to audio by integrated loudspeaker. I can't use the keys "sound on my computer. If I click on I have a icon "forbiden".  Can you help me

    Si vous tappez sûr le cle <<option>> et cliquez vôtre souris de l'icon de haut-parleur
    de le haut partie de sa Desktop, vous pouvez voir les choix pour le son: les haut-parleurs internales, Line out et Digital Out. C'est tout ! Ou cliquez de la Pomme a gauche, choissisez Préferences, et Son, et voila..... le meme chose.....
    Merci d'avoir choisi Apple
    John B

  • I just set up a wireless network using an airport express. How can you change the network name

    How can you change the name of a wireless network set up with an airport express

    Yes, you can. If you use the current AirPort Express, Apple says that you can connect up to 50 devices. Realistically, make that 25-30 or so before the speed really begins to drop.
    Remember that you will have to reset the modem though, before you connect it to the AirPort Express as the modem "remembers" the settings for your computer.

  • How can I drop the key board from my calendar. The normal lower right key stopped working

    How can I drop the key board from my calendar? The normal lower right key stopped working.

    You can install this extension to make it easier to edit userChrome.css:
    * ChromEdit Plus: http://webdesigns.ms11.net/chromeditp.html
    The file needs to have this code:
    <pre><nowiki>@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* only needed once */
    #personal-bookmarks #bookmarks-menu-button { display:none !important; }</nowiki></pre>
    You can reach the profile folder this way:
    *Help > Troubleshooting Information > Profile Directory: Open Containing Folder
    The file userChrome.css needs to be in the chrome folder in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder], so if the chrome folder is missing then you need to create a folder with the name chrome.

  • Can you see the problem?

    i'm trying to write a simple image viewer application.
    Can you see the problem. i can't. i'll appreciate any advice or help?
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.io.*;
    public class SimpleViewer extends Frame {
         protected Image awtImage;
         public void loadAndDisplay(String filename) {
              Image img = readImage(filename);
              awtImage = img;
              int width = img.getWidth(this);
              int height = img.getHeight(this);
              displayImage(img, width, height);
         public void displayImage(Image img, int width, int height) {
              addWindowListener(
                   new WindowAdapter() {
                        public void windowClosing(WindowEvent e){
                             System.exit(0);
              setTitle("Simple Viewer ");
              pack();
              setSize(new Dimension(width, height));
              show();
              repaint();
         public image readImage(String filename) {
              Image image = Toolkit.getDefaultToolkit().getImage(imageName);
              MediaTracker imageTracker = new MediaTracker(this);
              imageTracker.addImage(image, 0);
              try{
                   imageTracker.waitForID(0);
              }catch(InterruptedException e){ return null;}
              return image;
         public void paint(Graphics g){
              Rectangle rect = this.getBounds();
              if(awtImage != null) {
                   g.drawImage(awtImage, 0,0,rect.width, rect.height, this);
         public static void main(String[] args){
              SimpleViewer ip = new SimpleViewer();
              if(args.length <1) {
                   System.out.println("Enter a valid image file name");
                   System.exit(0);
              ip.loadAndDisplay(args[0]);
    }

    check this line and tell me what you see... after all, it's the source of your compiler errors...
    public image readImage(String filename) {
              Image image = Toolkit.getDefaultToolkit().getImage(imageName);once you figure that out, it will work...
    ( hint : check variable names and capitalization of names )
    - MaxxDmg...
    - ' He who never sleeps... '

  • How can you shrink the size of an upright picture to make it smaller without losing any of the detail in it??? At the moment, if I view them on my laptop, landscape photos fill the screen, but portrait photos only show the middle part.

    How can you shrink the size of an upright picture to make it smaller without losing any of the detail in it (in Slideshow)??? At the moment, if I view them on my Mac Laptop, landscape photos fill the screen, but portrait photos only show the middle part, so I loose the top and bottom of the picture.  Have tried cropping, but that means I lose top and bottom part of the picture, so that is not the answer!!

    Homestly haven't a clue what's going on there. 
    Try trash the com.apple.iPhoto.plist file from the HD/Users/ Your Name / library / preferences folder.
    (On 10.7: Hold the option (or alt) key while clicking on the Go menu in Finder to access the User Library)
    (Remember you'll need to reset your User options afterwards. These include minor settings like the window colour and so on. Note: If you've moved your library you'll need to point iPhoto at it again.)
    What's the plist file?
    For new users: Every application on your Mac has an accompanying plist file. It records certain User choices. For instance, in your favourite Word Processor it remembers your choice of Default Font, on your Web Browser is remembers things like your choice of Home Page. It even recalls what windows you had open last if your app allows you to pick up from where you left off last. The iPhoto plist file remembers things like the location of the Library, your choice of background colour, whether you are running a Referenced or Managed Library, what preferences you have for autosplitting events and so on. Trashing the plist file forces the app to generate a new one on the next launch, and this restores things to the Factory Defaults. Hence, if you've changed any of these things you'll need to reset them. If you haven't, then no bother. Trashing the plist file is Mac troubleshooting 101.

  • Can you use the same Apple ID on more than one MacBook Pro for updates and applications?

    We just got a few new MacBook Pro's and when I went to install updates it said I need to make an Apple ID.  Can you use the same Apple ID and email address for that Apple ID on multiple machines, or do I need them both to be unique per machine?  I'm not sure how that works when you have multiple machines.

    An Apple ID is a user name you use for everything you do with Apple. Creating an account for an Apple service, such as the iTunes Store or the App Store, creates an Apple ID. Apple ID allows you to access other Apple services.   So you can use the same Apple ID for up to 10 Macs associated with it.
    To create an Apple ID you need to enter  your full name and your primary email address as your Apple ID. This will be used as the contact email address for your account.

  • How can we remove the key from the dataset which has json

    uid
    id
    Json
    4588
    51
    { "key": "1/0/234", "element1":{ "a":10 "b": "test1" } }
    4589
    52
    { "key": "1/0/234", "element1":{ "a":10 "b": "test1" } }
    4590
    53
    { "key": "1/0/234", "element1":{ "a":10 "b": "test1" } }
    I have the above dataset resulting from merge operation .
    UID -Integer data type
    ID- Integer data type
    Json- String data type holding json document
    How can I remove  the " key" element from the json field  and make my dataset look like 
    Expected output which will strip of key value pair from the json column
    uid
    id
    Json
    4588
    51
    { "element1":{ "a":10 "b": "test1" } }
    4589
    52
    { "element1":{ "a":10 "b": "test1" } }
    4590
    53
    { "element1":{ "a":10 "b": "test1" } }
    Mudassar

    Hello Mudassar,
    In SQL Server / T-SQL we don't have a native JSON support, so you would have to implement a solution on your own = parsing the string and remove the "Key" + it's value.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

Maybe you are looking for

  • Animated GIF with hover?

    Here is an animated GIF where you can stop and start it when you hover over it.  I know how to make them in PSD but not sure how to do it with the hovering (scroll down to see it on page below): http://www.sbnation.com/2014/1/16/5304078/breaking-madd

  • Functional knowlwdge for abap/xi developer

    hi i am new to sap. I am learning abap and xi. I was asked a couple of times what are the modules you are comfortable in. please guide me where i can get the functional overview of the different modules necessary in a abap developer perspective. plea

  • SAPGUI: Show appserver name instead of host name?

    Hi guys, We have recently migrated our SAP system so that we have 3 application servers on the 1 host. In SAP GUI, when a user is loggod on to one of these application servers, the <i>host</i> name is shown in the bottom-right of the window. Is there

  • New updated version of iTunes

    SJ has annouced that tonight (Wednesday) an updated version of iTunes will become available. It will support new products and +*the installation of your own ringtones on the iPhone*+! Perhaps it will also solve the recent issues effecting some of the

  • CAD Interface functionalities

    Hi Plm Experts, Can any body please explain me how to use CADInterface and How it will work.i appreciate for early reply.