ArrayList = Vector  | ArrayList Vector | ArrayList == Vector

I want to know when we should use ArrayList instead of Vector, or vice-versa. I know that Vector is synchronized and ArrayList is not. But someone said that ArrayList is faster. This case also happens with Hashtable and HashMap.
Can anybody help me?

In new code, use ArrayList unless you are using something in Swing (or anything else) that was defined to require a Vector (done that way because Vector was the only thing around at the time, I think). If you want a synchronized List, use:
List myList = Collections.synchronizedList(new ArrayList());Same for Hashtable/HashMap
Map myMap = Collections.synchronizedMap(new HashMap());

Similar Messages

  • Reading Individual Lines of Text Into An ArrayList or Vector From A File

    I am trying to read each individual line of text of a .txt file into an ArrayList or Vector. I seem to get the same results no matter which Object I am using (ArrayList or Vector). The text file is a comma-delimited text file to be used as a database. I want to separate each line as an individual record then dump it into an ArrayList or Vector and have them loop through a StringTokenizer() class so that I can be sure each line has the correct number of fields before I commit it to a serialization file. Currently, the proper amount of records seems to be forming in the initial part of the program, I am just remiss at properly placing them in the Vector, or StringTokenizer classes so I can further manipulate them. I'm using the LineNumberReader class to get line numbers to use as record numbers and for loop indexes. I'm not sure (obviously) if this is a correct way to do it or not.
    Any help is greatly appreciated in advance.
    Thanks for all your time.
    int n = 0;
              try {
                    * read each individual line and count it as a separate record. 
                    * place each record into an array or may be a string if it has 9 tokens
                    * if a record hasn't got 9 tokens, it isn't a record
                    * place each array or string into a Vector
                   in = new LineNumberReader(new FileReader(filename));
                             while ((record = in.readLine()) != null) {
                             n = in.getLineNumber();
                             rawData = new Vector();     
                             for (int i = 0; i < n; i++) {
                                  rawData.add(record);     
                             if (record == null)
                             break;
    *The following System.out.println() statement shows that all lines are correctly retrieved from the text file
    *as separate records
                        System.out.println("Record No. " + n +  "= " + record);     
                   //Debug
    /** When these print lines execute it reveals that only the last record has been inserted into the Vector as
    *    many times as I have records in the text file.
                        System.out.println("Number of Records = " + n);
                        System.out.println("VectorSize = " + rawData.size());
                        System.out.println("First rawDataElement = " + rawData.firstElement());
                        System.out.println("Second rawDataElement = " + rawData.get(1));
                        System.out.println("Third rawDataElement = " + rawData.get(2));
                        System.out.println("Fourth rawDataElement = " + rawData.lastElement());
    *  Next run each record through a StringTokenizer to be sure that there the correct number of fields present
    *  If it contains the correct number of fields, dump it into an alternate ArrayList or Vector.
    *  As it is now, the StringTokenizer gives a NullPointerException
                        for (int i = 0; i < n; i++) {
                             StringTokenizer recordSet = new StringTokenizer((String) table.get(n), ",");
                                 while (recordSet.hasMoreTokens()) {
                                     if (recordSet.countTokens() == 9) {
                                           data = new Vector();
                                           data.add((Object) recordSet.nextToken(","));
                                           System.out.println("Vector data size = " + data.size());
                                           System.out.println("Second dataElement = " + data.get(0));
                            System.out.println("String Tok recordSet = " + recordSet.countTokens());                                  System.out.println("Number of Records = " + n);
                        System.out.println("First dataElement = " + data.firstElement());
                        System.out.println("Second dataElement = " + data.get(0));
                        System.out.println("Third dataElement = " + data.get(2));
                        System.out.println("Fourth dataElement = " + data.lastElement());
                   } catch (FileNotFoundException e) {
                        System.out.println(e);
                   } catch (IOException e) {
                        System.out.println(e);
         }

    I think your logic is broken.
    rawData = new Vector();
    creates a new instance of Vector for every record.
    Your add() within a for loop adds the same record to the Vector n times. I think what you really want is something like this:in = new LineNumberReader(new FileReader(filename));
    rawData = new Vector();
    while ((record = in.readLine()) != null) {
        n = in.getLineNumber();
        rawData.add(record);     Mark

  • Method to return ArrayList or Vector doesn't work, why?

    Hi, I try to return a ArrayList or Vector from a method but it does not work.. wondering why and how to fix it? Thanks:)
    class Class1{
          public static main(...){
              Class2 test = new Class2();
              ArrayList<String> resp = test.class2method(...);
              if(resp.get(4).equals(...)) {        
    class Class2{
        public ArrayList class2method(int NumInt1, int NumInt2, ...) {
           ArrayList<String> arrayTesting = new ArrayList<String>(13);
           responses.set(2, Integer.toString(NumInt1));
           responses.set(3, Integer.toString(NumInt2));
           responses.set(4, Integer.toString(NumInt3));
           responses.set(5, Integer.toString(NumInt4));
           responses.set(6, Integer.toString(NumInt5));
           return responses;
    }

    what is responses? don't you want to return
    arrayTesting?yes, responses is arrayTesting, sorry did notmention
    that.what do you mean? is the code you posted a typo or
    what you actually have in your code?It's more than 1000 lines codes so I decided not to posted them but here is part of them. My point is that i tried to return a ArrayList or Vector even with a simple code, it does not work. Thanks for your help.
    public class DemoScript {
        public DemoScript() throws IOException {
            // register the shutdown hook
            Runtime.getRuntime().addShutdownHook(new Thread() {
                public void run() {
                    System.out.println("close prog");
                     endApp();
        public void endApp() {
            System.out.println("done!");
            System.exit(0);
         public static void main(String[] args) {
              Parameters p = new Parameters();
              VMF vm = null;
                   //Elements: [0]time, [1]MsgType, [2]NumInt1, [3]NumInt2, [4]NumInt3, [5]NumInt4, [6]NumInt5, [7]NumLong,
                   //               [8]String1, [9]String2, [10]String3, [11]String4, [12]String5
    //               ArrayList<String> responses = new ArrayList<String>(13);
              try {
                   MyScript my = new MyScript();
                   if(args.length == 5) {
                       p.vmHost = args[1]; p.vmPort = Integer.parseInt(args[2]);
                       p.guiHost = args[3]; p.guiPort = Integer.parseInt(args[4]);
                  } else if(args.length == 4) {
                       p.vmHost = args[1]; p.vmPort = Integer.parseInt(args[2]); p.guiHost = args[3];
                  } else if(args.length == 3){
                       p.vmHost = args[1]; p.vmPort = Integer.parseInt(args[2]);
                  } else if(args.length == 2){
                       p.vmHost = args[1];
                  } else {
                       System.out.println("Usage: java MyScript [port #] [voice mail hostname] <voice mail socket #> <GUI hostname> <GUI socket #>");
                       System.out.println("Default: <voice mail socket #> = "+p.vmPort+", <GUI hostname> = "+p.guiHost+", <GUI socket #> = "+p.guiPort);
                       System.exit(-1);
    //               String hostname;
                   //int port;
                   /* Check for input arguments */
                   //if(args[0] != null){
                   //     port = Integer.parseInt(args[0]);
                   //     hostname = args[1];
                   //} else {
                   //     port = 2000;
                   //     hostname = "10.0.0.228";
                   //System.out.println("tews");
                   vm = new VMF(p.vmHost, p.vmPort, p.guiHost, p.guiPort);
                   vm.logon();
                   //vm.portAbort(4);/*
                   vm.portCapture(3, 0);
                   //vm.portAbort(4);/*
                   //vm.portOnhook();
                   //vm.portOffhook();
                   ////vm.portStop(3);  //to stop a port current operation
                   //vm.portWaitring(); //vm will not resp until port detects ring
                   //vm.portOffhook();
                   //vm.portGetdigits(5, 7);
                   //vm.portDialdigits("201");
                   //for(int i=0;i<100000000;i++);
                   //vm.portCallprogress(3, 0, 10);
                   //System.out.println("d");
                   //for(int i=0;i<1000000;i++);
                   //vm.portGetdigits(5, 7);
                   //vm.portRecordfile(30, 1, "\\\\kanapak.ctlinc.local\\VMfiles\\test.wmv");
                   //vm.portClearDTMF();
                   //vm.portPlayfile("\\\\kanapak.ctlinc.local\\VMfiles\\test.wmv");
                   //vm.portPlayprompt(2);
                   //vm.portSpeaknumber(3845);
                   //vm.portSpeakdigits("1639123478866478909");//75655656566657867867*");
                   //vm.portExternalcall(4, "933");
                   ArrayList<String> response = vm.portInternalcall(2, "201");
                   System.out.println(response.get(4));
                   if(response.get(4).equals("DONE")) {
                        vm.portPlayprompt(1); vm.portPlayprompt(2);
                   } else if(response.get(4).equals("GONE")) {
                   vm.portSpeakttsstring("hello. This will create ");//a project with all of the proper SWT and JFace imports. Version 4.1.1 latest build released (SWT visual inheritance, enhanced SWT GridLayout support, non-visual beans, custom !!!SWT widgets, code generation enhancements, expose property, etc.)");
                   vm.portRelease();
                   vm.logoff();
                   vm = new VMF(p.vmHost, p.vmPort, p.guiHost, p.guiPort);
                   vm.logon();
                   vm.portCapture(Integer.parseInt(args[0]), 0);
                   vm.portOnhook();
                   vm.portOffhook();
                   //          vm.portGetdigits(5, 7);
                   //vm.portRecordfile(30, 1, "\\\\kanapak.ctlinc.local\\VMfiles\\test.wmv");
                   //vm.portClearDTMF();
                   //vm.portPlayfile("\\\\kanapak.ctlinc.local\\VMfiles\\test.wmv");
                   vm.portPlayprompt(86);
                   //          vm.portSpeaknumber(3845);
                   //vm.portSpeakdigits("1639123478866478909");//75655656566657867867*");
                   //vm.portExternalcall(4, "933");
                   //vm.portInternalcall(9, "82045");
                   //vm.portSpeakttsstring("hello. This will create");// a project with all of the proper SWT and JFace imports. Version 4.1.1 latest build released (SWT visual inheritance, enhanced SWT GridLayout support, non-visual beans, custom !!!SWT widgets, code generation enhancements, expose property, etc.)");
                   vm.portRelease();
                   vm.logoff();
              } catch (IOException e) {
                   e.printStackTrace();
              } catch (InterruptedException e) {
                   //catch "STOP PORT"
                   vm.logoff();
    class VMF {
        public ArrayList<String> portInternalcall(int rings, String dial_string) {
             if (logon_status == 0) {
                   System.err.println("Error: logon required");
                   logoff();closeAndExit();
              } else if (capture_status == 0) {
                   System.err.println("Warning: portCapture required");logoff();closeAndExit();
              } else if (rings <1 || rings >999 || !checkDigits(dial_string)) {
                   System.err.println("Warning: portInternalcall( [1-999] , \"[0-9,A-D,F,P,a-d,f,p,*,#]\" )");
             breakString(dial_string);
             ostruct.write("", "IVR", "123", 188, captured_port, rings, 0, 0, 0, 0, str1, str2, str3, str4, str5);
             sendToGUI("s", "", "IVR", "123", "188", Integer.toString(captured_port),
                       Integer.toString(rings), "0", "0", "0", "0", str1, str2, str3, str4, str5);
             readStream();
             recToGUI("r", Integer.toString(MsgType),Integer.toString(NumInt1),Integer.toString(NumInt2),
                        Integer.toString(NumInt3),Integer.toString(NumInt4),Integer.toString(NumInt5),
                        Integer.toString(NumLong),String1,String2,String3,String4,String5);
              responses.set(2, Integer.toString(NumInt1)); responses.set(3, Integer.toString(NumInt2));
              responses.set(4, Integer.toString(NumInt3)); responses.set(5, Integer.toString(NumInt4));
              responses.set(6, Integer.toString(NumInt5));
              return responses;
    }

  • How to use Vector or other ArrayList etc to store my JTree??

    How to use Vector or other ArrayList etc to store my JTree??
    Dear friends,
    I have following I posted before, but not get satisfactory answer, so I modify and repost again here.
    I have following code can add classes and students in the JTree,
    in class Computer Science, it has student Bill Brien,
    in Math, no,
    Then I I add Student Nancy, Laura, Peter into Computer Science Class,
    add AAAA, BBB, CCC into Math class,
    I create a new class called Chemistry, then I add DDD int Chemistry;
    so this JTree is dynamically changed,
    [1]. How can I dynamically save my current JTree with all above tree structure and its nodes in a Vector or ArrayList(not sure which one is best)??
    see code below:
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    public class ModelJTreeTest extends JFrame {
      private JTree tree;
      private DefaultTreeModel model;
      private DefaultMutableTreeNode rootNode;
      public ModelJTreeTest() {
        DefaultMutableTreeNode philosophersNode = getPhilosopherTree();
        model = new DefaultTreeModel(philosophersNode);
        tree = new JTree(model);
        JButton addButton = new JButton("Add Class/Students");
        addButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            addPhilosopher();
        JButton removeButton = new JButton("Remove Selected Class/Students");
        removeButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent event) {
            removeSelectedPhilosopher();
        JPanel inputPanel = new JPanel();
        inputPanel.add(addButton);
        inputPanel.add(removeButton);
        Container container = getContentPane();
        container.add(new JScrollPane(tree), BorderLayout.CENTER);
        container.add(inputPanel, BorderLayout.NORTH);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(400, 300);
        setVisible(true);
      private void addPhilosopher() {
        DefaultMutableTreeNode parent = getSelectedNode();
        if (parent == null) {
          JOptionPane.showMessageDialog(ModelJTreeTest.this, "Select Class", "Error",
              JOptionPane.ERROR_MESSAGE);
          return;
        String name = JOptionPane.showInputDialog(ModelJTreeTest.this, "Add Class/Students:");
        model.insertNodeInto(new DefaultMutableTreeNode(name), parent, parent.getChildCount());
      private void removeSelectedPhilosopher() {
        DefaultMutableTreeNode selectedNode = getSelectedNode();
        if (selectedNode != null)
          model.removeNodeFromParent(selectedNode);
      private DefaultMutableTreeNode getSelectedNode() {
        return (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
      private DefaultMutableTreeNode getPhilosopherTree() {
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Students");
        DefaultMutableTreeNode ancient = new DefaultMutableTreeNode("Computer Science");
        rootNode.add(ancient);
        ancient.add(new DefaultMutableTreeNode("Bill Brian"));
        DefaultMutableTreeNode math = new DefaultMutableTreeNode("Maths");
        rootNode.add(math);  
        DefaultMutableTreeNode physics = new DefaultMutableTreeNode("Physics");
        rootNode.add(physics);
        return rootNode;
      public static void main(String args[]) {
        new ModelJTreeTest();
    }the actual Tree dynamically created somehow looks like following:
                             |            1.Peter
                             |---CS---    2. Nancy
                             |            3. Laura
                             |            4.Brian
                             |
    Root(University): -------|---Math- 1.AAA
                             |            2.BBB
                             |            3.CCC
                             |
                             |
                             |---Chemistry- 1. DDDThanks a lot
    Good weekends

    you can't directly store a tree in a list.Ummm... Just to be contrary... Yes you CAN store a tree in a table.... In fact that's how the windows file system works.
    Having said that... you would be well advised to investigate tree data-structures before resorting to flattening a tree into a list.
    So... Do you have a specific requirement to produce a List? Your umming-and-erring about Vector vs ArrayList makes it sound like you're still at the stage of choosing a datastructure.
    Cheers. Keith.

  • ArrayList   Vs LInked List    Vs   Vector

    Which is one is faster -ArrayList ,LInked List ,Vector
    Thank you

    arun240 wrote:
    Adding new elements is pretty fast for either type of list. For the ArrayList, doing random lookup using "get" is fast, but for LinkedList, it's slow. It's slow because there's no efficient way to index into the middle of a linked list. When removing elements, using ArrayList is slow. This is because all remaining elements in the underlying array of Object instances must be shifted down for each remove operation. But here LinkedList is fast, because deletion can be done simply by changing a couple of links. So an ArrayList works best for cases where you're doing random access on the list, and a LinkedList works better if you're doing a lot of editing in the middle of the list.Mostly right, but:
    - adding elements to the end of an ArrayList is pretty fast as well.
    - removing elements from the end of an ArrayList is pretty fast
    - occasionally adding an element to an ArrayList can trigger a resize of the internal array which makes it a bit slow-ish, but this evens out over time
    - get() for elements at the very beginning or end (or very near that) is reasonably fast for LinkedList as well
    - deleting from a LinkedList at a random position using an Iterator is pretty fast
    - deleting from a LinkedList at a random position using remove(int) is pretty slow, as it first needs to do the equivalent of get(int), which is slow
    The moral of the story: learn your data structures well, even if it's boring. It has many implications.
    And we're not even going into HashMap/Queue/Heap territory here.

  • ArrayList vs Vector

    which one do you prefer? and why?

    ArrayList. It's more efficient, because it's not synchronised. (And synchronising an ArrayList is apparently still more efficient than using a Vector. The only reason one would possibly prefer a Vector is for writing applets which don't require plugins).

  • Use ArrayList vs Vector

    I'm writing an application that accept multiple connections.
    To check the connections I have a thread that check these connections if they are in use, i iterate over these connections and if they are not used for a periode of time, i close this connection and remove them from my list and iterate further.
    If i use a Vector to collect the connections, everything goes fine, but if i use a Arraylist, i get a concurrentmodificationexception, i now, this is normal, because the failfast of the iterator, so, i used the synchronize method of collections, but i got the same exception,
    any suggestions to make ik work with an ArrayList.

    If i can make it work with a list i'me happy, i will try it with a linked list, thx
    Heres the code of the methode
    public void run() {
    while (true) {
    try {
         Enumeration enum = null;
         sleep(frequency);
         long currTime = System.currentTimeMillis();
         enum = TimeoutInputStream.instanceList.elements();
         while (enum.hasMoreElements()) {
    TimeoutInputStream stream =
         (TimeoutInputStream) (enum.nextElement());
    //ITERATOR FAILS HERE
         long lastActive = stream.getLastActive();                    System.out.println(".");
         if (lastActive == 0) {
              stream.setLastActive(currTime);
         } else if ((currTime - lastActive) > timeout) {
              stream.abort();
    //HERE DO I REMOVE THE CONNECTION OUT OF THE LIST
              System.out.println("Timeout: input stream aborted");
         } catch (InterruptedException e) {
              System.out.println(e);

  • Vector or ArrayList  use for dropdown with more than 1000 entries

    Hi Friends
    I am having more than 1000 entries of different TimeZone's which i need to display in a dropdown list.
    i am not able to decide whether i need to use a Vector or Arraylist for storing these values.
    please let me know which one will be best suited to use in case the list entry is more than 1000 characters.
    waiting for a positive reply from your side.
    Thanks & Regards
    Vikeng

    A JComboBox can be constructed from a Vector (rather than any other sort of List) without having to implement your own ComboBoxModel. (JList is similar).
    I agree with kajbj - a control like this with a thousand entries is rather poor interface design. One exception might be if the entries are sorted in some way, and you "jump" to the appropriate place in the list as the user types.

  • Storing Coordinates as integers in a Vector or ArrayList??

    Greetings all,
    I am trying to store a set of (x,y) coordinates in either a vector or an arraylist but don't really know which one is better or really the proper way to be doing it ... from my understanding firstly these numbers are stored as objects rather than integers, but i need them as integers because i would like to plug them into equations etc., from my understanding of vectors the code is something like this:
    Vector v = new Vector();
    v.addElement(0);
    v.addElement(1);
    v.addElement(2);
    v.addElement(3);which results in a vector like v=[0,1,2,3] which if i'm not mistaken are objects not integers, but what if i want a vector which stores numbers as v=[(0,0), (1,0), (2,0), (3,0)] that are integers?
    Your help is much appreciated.
    Thanks.

    Take the collections tutorial: [http://java.sun.com/docs/books/tutorial/collections/index.html]
    Prefer collections framework classes like ArrayList over older legacy classes like Vector.
    demo:
    import java.awt.Point;
    import java.util.*;
    public class ListExample {
        public static void main(String[] args) {
            List<Point> points = new ArrayList<Point>();
            points.add(new Point(1,2));
            points.add(new Point(5,3));
            System.out.println(points);
    }

  • Should we use ArrayList or Vector?

    Should we use ArrayList or Vector in web programming environment?
    thanks,

    I used to use ArrayList everywhere since it was a newer class and recommended in books, but use Vector now because it is used in several key environments: Java 1 (Web browsers), Swing and J2ME. In Java2, Vector was retrofitted to use the Collections framework, so Vector implements List.
    Anyway, you should probably deal with only the List interface anyway so whichever you decide will be localized. That way, if Sun suddenly stops supporting Vector, you will only need to make a change in one place.
    List mylist = new Vector();

  • Performance of ArrayList with Vectors

    Tell me any one that , is ArrayList Performance is Better then Vectors ? and if yes why so?

    yes, again. As long as authors of introductory tests don't stop using Vector in their examples and Sun doesn't change the Swing method arguments to take a List instead of hardcoding a Vector (enabling people to finally abandong the thing without recoding every ListModel, TableModel, etc. they want to use) we'll keep seeing this.
    Vector should be deprecated, in fact it should have been removed already (maybe with the name just becoming a wrapper for a synchronized ArrayList to maintain backwards compatibility for a few releases).

  • 2D Vector or ArrayList

    Evening,
    Is there anything like a 2D Array in the ArrayList or Vector??

    Hi All.
    I am translating soem code from C++ to JAVA.
    in C++, I used vector< vector <int> > to create a sparse matrix / 2D array.
    I know you can make a vector of vectors in JAVA but i have been unable to get the individual elements. For example. I have:
    =========================
    Vector matrix = new Vector();
    for(){
    Vector row = new Vector();
    ... Do some to initiate row so that it has size > 1...
    matrix.add(row);
    =========================
    I can only do matrix.get(int), which gives me the entire row, but i can't do matrix.get(int).get(int) etc.... is there any way I can extract the[i] i,j element if a sparse matrix is set up this way or would i have to totally restructure?
    Thanks

  • Vector or ArrayList?

    Hi
    The J2ME-Polish framework provides an implementation of ArrayList. I am concerned in our project about the resource usage. Does anybody of you has experience with the ArrayList? Does it use less resources than the Vector?
    Kind regards
    Michael

    Hi
    The docs from J2ME Polish state that "de.enough.polish.util.ArrayList offers a fast alternative for Vector." I don't think though you would notice any difference when using one or another; you would have to make heavy use of this classes, which is not indicated in J2ME.
    I don't know if we can apply the J2SE concepts for this two classes, but you should read this article and decide what to use: http://www.javaworld.com/javaworld/javaqa/2001-06/03-qa-0622-vector.html
    Mihai

  • ArrayList / Vector

    Hello All,
    I put the result from the database as a list of transfer objects ...is it better to use ArrayList or Vector to store them and use them in my action, jsp etc......I know using vector adds the synchronization overhead but someone advised that storing data in a vector is more advantageous...
    Help is greatly appreciated...
    Thanks,
    maithri...
    Message was edited by:
    Maithri

    Typically, Vector is only recommended when your code needs to run in an older jvm, say version 1.2. Otherwords, array list is almost always recommended.
    Even when you need synchronization, the ArrayList can become synchronized, and since you have to do that explicitly, a maintainer knows that you are doing operations that require synchronization, as opposed to using Vector, where you get synchronization whether you want it or not, so that doesn't tell the maintainer much.
    - Adam

  • Why Arraylist better than vector?

    Hi,
    Why Arraylist better than vector?.....i heared about it that fast then vector......how it's possible ?.....how can we find out....?

    ArrayList is faster then vector.because in vector class all the methods are synchronized.so it is obvoiusly slow.Not everything that appears obvious is actually true.
    add more object into Arraylist and vector say(1000).we have a method called currentTimeMillis() in System class .
    use that and try to iterate both (arraylist,vector) objectIf you had ever done this test (use 100000 rather than 1000 as the resolution of currentTimeMillis() is too course), then you would know that Vector is faster more often than not:new List()      new List(N)
    Add+Iterate     Add+Iterate     Add Only        Iterate Only
    ArList  Vector  ArList  Vector  ArList  Vector  ArList  Vector
    609     516     250     250     63      94      109     125
    562     516     250     266     78      94      125     109
    609     500     266     250     78      93      141     110
    532     547     250     265     62      93      110     125
    547     500     250     265     78      94      125     109
    547     500     266     265     62      94      109     109
    547     500     250     281     78      78      125     109
    ms averaged over 7 runs:
    565     511     255     263     71      91      121     114
    jdk 1.4.2_07 Windows client
    N = 1000000 The vector wins when you don't know the size it's going to end up (its capacity increases by 2 rather than 1.5 each time it grows, so there are fewer array allocations). There's no significant difference between the two on iteration. It is only when you are adding to a Vector that already has sufficient capacity that there's a measurable difference.
    Anything that requires contension on the locks will probably adversely affect the Vector's performance.
    Pete

Maybe you are looking for

  • Having trouble getting my Lightroom 5.0 upgrade to accept my Lightroom 4.4 serial number.

    I am having trouble getting my Lightroom 5.0 upgrade to accept my Lightroom 4.4 serial number. I recently installed Windows 8, 64 bit on a second solid state HD on my computer (had a virus problem for which I had to format C and reinstall everything)

  • Query in sql

    oracle database version 10.2.0.1 on windows server 2003 segment_id is a common column in two tables "segment" and "mv_cat_seg_reg_prod" mv_cat_seg_prod can have more than a single row for each segment_id whereas segment table has one row for each seg

  • HISTORY MANAGE CHECK BOX

    HI MASTERS, WHY WE UUSE HISTORY MANAGE CHECK BOX IN ASSET MASTER, AND IN ASSET CLASS, I THINKING  IT IS USED FOR UPLOADING THE ASSETS TO ASSET HISTORY SHEET IS IT. PLEASE GIVE REPLY THIS , POINTS WILL B ADDED.

  • Trouble downloading books

    Hi, I have a sony e-reader PRS-T1, I have some books in my PC and have tried to downloading into the e-reader but they don´t show and after I disconected from the PC it even shows me the books I deleted, can anyone help me or tell me how to fix this

  • Drivers for LW261UA Pavilion dv6-6110us

    I did that but I still have VGA hardware issues, cannot connect to the internet. please help. I have been trying for days!!!