Chosing from Vectors, HashMaps or Arrays

Hi All,
I have to decide on which of these to use for my problem. I want a Collection that holds values like
[Name, year of Birth]
["Tom", 1952]
["Dick", 1972]
["Harry", 1992]
.where the first element is a String type and its related element is an integer ...
the age old solution looks like using a 2-D array ... but in my case the list has to expand vertically and it could be possible that I have more data values laterally as well like "Age" field added up
["Tom",  1952, 53, ...... ]
.I am not able to make up my mind as to chosing between Vectors or Hashmaps or Lists for this situation .... I want to avoid usng a n-D array and instead use some of the features offered by Java ...
since I am relatively new to Java ... please explain why one should use a vector or a hashmap for this

1. Definitely not Vector, unless you need synchronization. Use ArrayList instead.
If your key is always the name, and the person may have many attributes, create a person class.
class Person
   String name;
   int YearOfBirth;
   String phoneNumber;
   //whatever 
}Put them in a HashMap with keys of name, and values of Person. Then if you want to add more attributes to Person, it is easy--your HashMap data structure won't change.
Map map = new HashMap();
map.put("Tom", new Person("Tom", 1952, "555-555-5555"));
//or, maybe better, so name isn't duplicated incorrectly:
Person person = new Person("Tom", 1952, "555-555-5555"));
map.put(person.getName(), person);

Similar Messages

  • How do I use "Trim Paths" after "Create Shapes from Vector Layer" on a strokes only layer?

    Hello,
    Adobe After Effects CC
    2014.0.2
    Version 13.0.2.3
    I have imported an illustrator file that was created in Illustrator CC 18.0.0. The file contains the outline of a logo. It is the logo with the fill set to none and the stroke set to 1px.
    I drag the logo_strokes.ai file onto the composition, right click, and click Create Shapes from Vector Layer.
    A new layer is created and in the Contents "drop down", a Fill 1 layer is created.
    When I select the Contents "drop down" and click Add / Trim Paths, a Trim Paths 1 layer is created.
    When I animate Trim Paths 1, it appears to animate the Fill layer, not the stroke.
    How do I get it to animate just the stroke, and not show a fill at all?
    Thank you.

    Thanks,
    I am reading and watching tutorials. Still stuck on that one point.
    Here are the images of the After Effects layers. The illustrator layer is the top layer.

  • How can I remove only the middle elements from a 2-D array?

    Hello all!
    We have had an issue at my work where some of our graphs featuring a Gaussian curve have an unusual rectangular distortion in the middle of the curve (sorry that I have no image to show you, the error is before my time at the company, and I've been asked to find a solution before it happens again). Basically, what should be a Gaussian curve is leveling off briefly and looking like a rounded square wave. We know what causes the distortion, so I only wish to remove the middle part, giving it the appearance of a Gaussian. It's odd, but it actually offers a good approximation of what we want. The graph is made from a 2-D array of Double values, and we can estimate the size of the leveled-area, so I figured that removing the middle elements from the graph would accomplish this. Does anybody know a way I can accomplish this?
    -Gobble
    LabView 8.5.1

    Raven,
    Thank you very much, I'll try that!
    -Gobble
    LabView 8.5.1

  • Combobox whose datasource is from an hashmap

    Hello
    I work on a J2EE/Struts2 project On a jsp, I have a combobox whose datasource is from an hashmap
    In the action, I can't find how can I get the selected item (the selected key of the object selected in my combobox) in order to load my object (with Hibernate)
    and manipulate my object
    Does anyone can help me?
    Thanks a lot
    Best regards

    Hi,
    Have a look into the link. It gives you some info regarding data mart from one system to another.
    http://help.sap.com/erp2005_ehp_04/helpdata/EN/80/1a6110e07211d2acb80000e829fbfe/frameset.htm
    Regards,
    Sunil

  • Unlink shapes from vector mask in PS CS 6

    Hi guys,
    Do you know how I can unlink the shape from vector mask like in Photoshop cs 4?
    cs6:
    cs4:
    This is especially interessting for if I want to move pattern overlay or something else. I hope you can help me.
    thx
    http://xd-artist.de

    It is relatively easy to create Collage PSD Template for Photoshop.  There are several ways to design them.  One way is to create image place holder layer with layer mask that you insert images into when you populate a copy of a template.  Photoshop support thousands of layers. 
    The way I do it is to user Alpha channels to map where images go. Photoshop only supports 53 Alpha channels so my collage templates are limited to 53 images. I populate my template using Photoshop scripts.  The Alpha channels are use to resize placed image files to fit the alpha channel sizes. Also to position the resized image and to virtually crop the resize images by adding the alpha channels to the image smart object layers. I have scripts that batch populate templates, Populate one and remain open in Photoshop for further tweaking. And a interactive script the allows you to select image as the template is being populated and tweak their placement and sizing.  The script also have options for adding text layer with filename over the images in one of 9 locations.  Layer styles can also be optionally added to image and text layers. Animated Templates are even possible.
    Photo Collage Toolkit: http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html
    One I populated today click on image for a Video Demo:

  • Creating shapes from Vector layers (.ai files)

    I am trying to make extrusions to an image.  I am new to Illustrator and have read that .ai files are the only ones that you can extrude in AE.  However when I bring in an .ai file and select create shape from vector layer, a grey square covers the shape.  I am assuming that it is a transparancy issue and it is just filling in the size of the .ai project.  I could be wrong though.  How can I fix this?

    You need a plain shape in AI. If you're using gradients, masks, clipping paths or other stuff it won't work. Please give us more info and possibly a screenshot of your ai file.
    Try this. Open up Illustrator. Take the pen tool and create a simple shape with a closed path. Import that single layer single path file into AE and see if it works. If it does, then show us a screenshot of your AI file and show all layers and expand out any groups. We'll try and help.

  • How to conver vector to Int array

    Hi
    I know toArray method can be used to convert vector to an array but what if I want to convert it to an int array?
    Vector v = new Vector();
    int r [] = new int [1];
    v.add(2);
    r = v.toArray()//gives errorHow can I cast it to return int Array rather than object array?

    Vector v = new Vector(10);
    for(int i = 0; i < 10; i++) {
        v.add(i);
    int r[] = new int[v.size()];
    for(int i = 0; i < r.length; i++) {
        String value = v.elementAt(i).toString();
        r[i] = Integer.valueOf( value ).intValue();
        System.out.println(r);

  • Converting a vector to an array

    hello :-)
    i am converting my vector into an array with this syntax:
    String[] lmname = (String[])name.toArray();
    and try to print my array with
    for(int i=0; i<lmname.size; i++)     
    System.out.println(lmname);
    unfortunately, i get this error:
    java.lang.ClassCastException
    what did i do wrong?

    -- you cannot do that...
    - if you still want to convert Vector into String[] then you can do this:
                 Vector v=new Vector();
               v.add("1");
               v.add("2");
               v.add("3");
               v.add("4");
               String strVector[]=new String[v.size()];
               for (int i = 0; i<v.size(); i++)
                       strVector=new String((String)v.get(i));
         for (int i = 0; i<strVector.length; i++)
         System.out.println (strVector[i]);
    ... By the way, you can use List instead of Vector,,,

  • Fetch the value from a HashMap through EL

    Hi,
    I have this question,
    how can we get a value from a HashMap through EL. is there any way to do that.
    for example i have a hashmap in my bean and i want to place the value of of certain attributes on the page. specific to the key values in the hashmap.

    Just by the key.
    ${bean.map.key}roughly resolves to bean.getMap().get(key).

  • How to extract data from vector?

    the following code returns vector as report which it recieves from TempSave.
    public Vector getQueryReport() throws ApplicationException, NoServiceException, CheckException
         Vector report =null;
         report =TempSave.getReportCE01();
         return report;
    }TempSave.java
    public class TempSave
       public static Vector getReportCE01()
       Vector dataSet = new Vector();
       dataSet.add(new SimplePOJO( "     B0210     ","     B.2)Acquisti di servizi     ","     6202254319     "));
       dataSet.add(new SimplePOJO( "     B0220     ","         B.2.1) per medicina di base     ","     582877602     "));
        return dataSet;
    } SimplePOJO is class which stores the passed value as in following function
    public SimplePOJO(String cOD_MOD, String dESC_MOD, String amt)
              this.COD_MOD = cOD_MOD;
              this.DESC_MOD = dESC_MOD;
              this.AMT = amt;
           }what i need is the last element "amt" ,saved as 6202254319,...,...     etc . Now i want to extract it from vector in getQueryReport(). So how can i do that?

    Try this:
    public Vector getQueryReport() throws ApplicationException, NoServiceException, CheckException
         Vector report =null;
         report =TempSave.getReportCE01();
         for(int i=0; i<report.size();i++)
                SimplePOJO pojo=(SimplePOJO)report.get(i);
                String amt=pojo.AMT; // if AMT in SimplePOJO is declared public  
         return report;
    }Hope this helps.

  • How many luns does mac OSX support from a single target (array) is it 255??

    How many luns does mac OSX support from a single target (array) is it 255?
    For example, if using the Dual-channel 4Gb Fibre Channel PCI Express card?  Is it 255, 512 or higher?  I know it uses the ATTO driver, but I can't find any documentaiton about the upper limits of how many luns this HBA can address from a single target array on a SAN.  Thanks.

    Hi,
    The card should be an ATTO 42ES whcih supports 255 LUNS per channel
    Here's the info from the attached link
    Consider the following Celerity FC host adapter guidelines:
    • ATTO 4-Gb and 8-Gb FC cards (PCI-X and PCIe only) are supported. • Latest HP-specific ATTO Celerity FC host adapter driver • Latest HP-specific ATTO Configuration Tool • A maximum of 256 targets per host adapter channel are supported. • A maximum of 255 logical unit numbers (LUNs) per host adapter channel are supported. • PowerPC- and Intel-based servers are supported.
    http://www.attotech.com/pdfs/MacOSFCconnEVA5697-7653.pdf
    Hope that helps
    Beatle

  • How to build n Tree from Vector

    Hi,
    i just want to build an n Tree from Vector.
    the Vector contains the elements {1,2,3,4}
    the tree should be like this (actually it should not be limited to 3 child, but just as an Example)
    i will be happy to use the jTree from Sun
    ++1
    +++2
    ++++3
    +++++4
    +++++4
    +++++4
    ++++3
    +++++4
    +++++4
    +++++4
    ++++3
    +++++4
    +++++4
    +++++4
    +++2
    ++++3
    +++++4
    +++++4
    +++++4
    ++++3
    +++++4
    +++++4
    +++++4
    ++++3
    +++++4
    +++++4
    +++++4
    +++2
    ++++3
    +++++4
    +++++4
    +++++4
    ++++3
    +++++4
    +++++4
    +++++4
    ++++3
    +++++4
    +++++4
    +++++4
    any Ideas?
    thanx.

    Massive crosspost. Answer here if you must.
    http://forum.java.sun.com/thread.jsp?forum=4&thread=444422

  • Boolean array from Vector element

    I have a Vector with each element being a boolean array. When I use the elementAt method it returns an object which I have to then cast in some way to a boolean array.
    Is this possible?
    Thanks for your help,
    Wallace

    By the way:
    - don't use Vectors if you don't have to. Other collections may be better suited and faster.
    - if you use Java 1.5, use Generics. Then you won't have to cast anymore.

  • Hashmap and array list problems

    This is an assignment I have to do and I do NOT expect anyone to do the coding for me. I am just looking for some direction as I have no clue where to go from here. Any guidance would be very welcomed.
    We were given code that used just an Array lisThis is an assignment I have to do and I do NOT expect anyone to do the coding for me. I am just looking for some direction as I have no clue where to go next. Any guidance would be very welcomed.
    We were given code and told to "Modify the MailServer so that it uses a HashMap to store MailItems. The keys to the HashMap should be the names of the recipients, and each value should be an ArrayList containing all the MailItems stored for that recipient. " Originally it was just an ArrayList named messages. There is also a MailClient and MailItem class.
    I think I can post the messages using the HashMap now, but can't test it. I get a compiler error saying else without if even though I have an if statement. Even if I can compile, I need to make sure I am on the right track with the getNextMailItem method. It is the one I am stuck on and if I can get it to work, I can probably modify the other methods.
    I would really appreciate feedback on that one method.
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    public class MailServer
         // Storage for the arbitrary number of messages to be stored
         // on the server.
         private HashMap messages;
         private ArrayList list;
         private MailItem item;
          * Construct a mail server.
         public MailServer()
             messages = new HashMap();
             list = new ArrayList();
          * Return the next message for who. Return null if there
          * are none.
          * @param who The user requesting their next message.
         public MailItem getNextMailItem(String who)
              Iterator it = list.iterator();
              while(it.hasNext())
                MailItem item = (MailItem)it.next();
                if(messages.containsKey(who));
                    return item;
               else
                   return null;
          * Add the given message to the message list.
          * @param item The mail item to be stored on the server.
         public void post(String name, MailItem item)
             if(messages.containsKey(name))
                    list = (ArrayList) messages.get(name);
                    else {
                        list = new ArrayList();
                        list.add(item);
                        messages.put(name, list);
    }[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    The way I understand this is that MailItems are stored in per user ArrayLists, and that the ArrayLists are stored in the HashMap, and use the username as a key,
    HashMap messages = new HashMap();
    //ArrayList userMailItems = new ArrayList(); this should not be declared here, only the messages mapso given a User name, you need to get the list of mail items for that user out of the hashMap, and then return the next MailItem from the list. So given that, you don't even need to Iterate over the list:
    public MailItem getNextMailItem(String who)
    ArrayList list = (ArrayList)messages.get(who);
    if(list == null || list.size() == 0)
    return null;
    //now we get the next item from the list, we can call remove, since it returns the object we are removing.
    MailItem item = (MailItem)list.remove(0);
    return item;
    }

  • How to get password as string back from encrypted password byte array.

    Hi All,
    I am storing encrypted password and enc key in the database.(Code included encryptPassword method for encryption and validatePassword method for validating of password). Problem is that for some reason i need to show user's password to the user as a string as he/she entered. But i am not able to convert the encrypted password from D/B to original String.
    Tell me if any body know how to get the string password back from the encrypted password byte array after seeing my existing encryption code.
    //********* Code
    private Vector encryptPassword(byte[] arrPwd)
    try
    // parameter arrPwd is the password as entered by the user and to be encrypted.
    byte[] encPwd = null;
    byte[] key = null;
    /* Generate a key pair */
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
    SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
    keyGen.initialize(1024, random);
    KeyPair pair = keyGen.generateKeyPair();
    PrivateKey priv = pair.getPrivate();
    PublicKey pub = pair.getPublic();
    /* Create a Signature object and initialize it with the private key */
    Signature dsa = Signature.getInstance("SHA1withDSA", "SUN");
    dsa.initSign(priv);
    /* Update and sign the data */
    dsa.update(arrPwd, 0, 12);
    /* Now that all the data to be signed has been read in, generate a signature for it */
    encPwd = dsa.sign();
    /* Now realSig has the signed password*/
    key = pub.getEncoded();
    Vector vtrPwd = new Vector(2);
    vtrPwd.add(encPwd);
    vtrPwd.add(key);
    return vtrPwd;
    catch (Exception e)
    private boolean validatePassword(byte[] arrPwd,byte[] encPwd,byte[] key) throws RemoteException
    try
    // arrPwd is the byte array of password entered by user.
    // encPwd is the encrypted password retreived from D/B
    // key is the array of key through which the password was encrypted and stored.
    X509EncodedKeySpec KeySpec = new X509EncodedKeySpec(key);
    KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN");
    PublicKey pubKey = keyFactory.generatePublic(KeySpec);
    /* Encrypt the user-entered password using the key*/
    Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
    sig.initVerify(pubKey);
    /* Update and sign the password*/
    sig.update(arrPwd, 0, 12);
    return sig.verify(encPwd);
    catch (Exception e)
    Help upto any extent would be appreciated.
    Thanx
    Moti Singh

    Hi All,
    I am storing encrypted password and enc key in the
    database.(Code included encryptPassword method for
    encryption and validatePassword method for validating
    of password). Problem is that for some reason i need
    to show user's password to the user as a string as
    he/she entered. But i am not able to convert the
    encrypted password from D/B to original String.No, you are not encrypting the password in your code, you are merely signing it.
    Tell me if any body know how to get the string
    password back from the encrypted password byte array
    after seeing my existing encryption code.It is impossible to retrieve the original text out of a signature.
    You should read up on some encryption basics in order to understand the difference between signing and encrypting. Then you can find examples of how to encrypt something here: http://java.sun.com/j2se/1.4/docs/guide/security/jce/JCERefGuide.html.
    Actually there is one class specifically for keeping keys secure, KeyStore http://java.sun.com/j2se/1.4/docs/api/java/security/KeyStore.html
    - Daniel

Maybe you are looking for