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).

Similar Messages

  • 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;
    }

  • Performance issues comparing two vectors

    I need some advice on what is the fastest way to compare two vectors. My question is all about performance;
    I have two vectors one(Vect A) of which has more than 20000 string values and the other Vector B would hold typically around 200 strings.I compare them both to find out if Vector B has values in Vector A and remove those.
    I iterate thro each element in a loop from the smaller to the bigger vector comparing element by element.But it takes a long time.
    Is there any quick way to do this comparison and can I use contains/compare methods instead of iterating thro the vectors.will it speeden up things
    Arn

    first of all, you should probably examine your collection choice and make sure that java.util.Vector is your best option (assumming you can change the class). Do not use a Hashtable as the previous poster suggested- it doesn't sound like you have a key/value type relationship in your elements, making a Map implementation superflous. Will there be duplicate elements in either Collection? If you will not have duplicate elements, you should probably use a Set collection instead of a List. Does your collection have to be thread-safe? If not, one of the unsynchronized collections should give you better performance (e.g. ArrayList should be quicker then Vector). For the best possible performance, you could use an ordered collection and write your own comparator, so that it does not iterate beyond what ever element assurres that there is no match (i.e. if the first element is "fred" in an ordered collection, you know there will be no match for "adam"). Sun has some good tutorials on the java.util.Collection package that will help you understand the benefit of each implemenation...
    although, and I suppose this is neither here nor there, I wouldn't use java objects to sort through 20K string items- sounds like storing them in a database might be superior. Take care.

  • 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();

  • JK Adobe TV - Top 5 Tips for Working with Vectors in CC

    Julieanne Kost has just blogged about her  Adobe TV video on working with shapes and paths in Photoshop CC.  It's actually not that new to Adobe TV, and has already had a lot of views, but we get a lot of questions here on the subject with CC, and there are some nice little tips in it.  I certainly learned a couple of things. :-)
    http://blogs.adobe.com/jkost/2014/01/top-5-tips-for-working-with-vectors-in-photoshop-cc.h tml
    http://tv.adobe.com/watch/the-complete-picture-with-julieanne-kost/top-5-tips-for-working- with-vectors-in-photoshop-cc/

    My apologies, but I really had no interest in a member's "answer", especially one that is so unhelpful.  Assuming that you were responding to me (we are the only two commenter's at this point), I would not be inclined to read the Creative Cloud offers since this is something that I am not interested in.  I bought the product the first day of offer, I did not rent it....just like I have in all the years past.

  • 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

  • I am using i 4 phone. recently I had a problem with my lap top and had formatted hard disk of it. Now I want to use sync data in my iphone back to itune n my lap top. how can I perform this task with out loosing data in my i phone.

    I am using i 4 phone. recently I had a problem with my lap top and had formatted hard disk of it. Now I want to sync data in my iphone back to itune on my lap top. how can I perform this task with out loosing data in my i phone.

    Hey floridiansue,
    Do you have an installed email program such as Microsoft Outlook?  If your email is through an online login, such as Gmail, etc, then one will have to create an email association with a program such as Microsoft Outlook on the PC for this Scan to Email system to function.
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------
    I am not an HP employee.

  • Is there a way to view Flash videos on my iMac without downloading Adobe Flash Player? I'm concerned about performance and security with Flash Player.

    Is there a way to view Flash videos on my iMac without downloading Adobe Flash Player? I'm concerned about performance and security with Adobe Flash Player.

    If the video is only available in a format that requires Flash player : then no.
    However, a great many can also be viewed in an HTML5 version, in which case http://hoyois.github.io/safariextensions/clicktoplugin/ or similar can be set up so that Flash never runs unless you specifically choose it to.

  • How to use's mail's "perform mail action with message"

    I can't for the life of me figure out how to use "perform mail action with message", I basically want to create a script that get's used on a rule from Mail, but nothing I try will work.
    This is what I started with...
    tell application "Mail"
    perform mail action with message msgs for rule theRule
    end
    end
    This doesn't compile i've seen an example of it being used like this...
    using terms from application "Mail"
    perform mail action with message msgs for rule theRule
    end perform
    end using
    this also doesn't compile, so I'm not sure what it's wanting

    This is one of those annoying things about programming - you have to arrange and spell things exactly right (this gets worse if you have fat fingers). You can look at the dictionary for Mail to see the specifics - in your example you are missing an "s" at the end of the word "message":
    <pre title="this text can be pasted into the Script Editor" style="font-family: Monaco, 'Courier New', Courier, monospace; font-size: 10px; padding: 5px; width: 720px; color: #000000; background-color: #E0E0E0; overflow: auto">tell application "Mail"
    perform mail action with messages msgs for rule theRule
    end tell
    </pre>

  • Is there any API for performing Assembly Completion with LPN

    Hi,
    Is there any API available for performing Assembly Completion with LPN..??
    Thanks and Regards,
    Ramnish.

    We had looked into doing something similar, and this post is the closest we found.
    https://community.qualys.com/thread/11816
    Basically you will need a middle-man between Qualys and ConfigMgr to house the data. This may be a new database, or a whole seperate platform. I expect this could easily be done with SQL and SSRS.
    Also note, database edits to the ConfigMgr database are
    not supported  by Microsoft, I would recommend using a central system to pull data from Qualys and ConfigMgr without modifying either.
    Daniel Ratliff | http://www.PotentEngineer.com

  • How can I color fill a sketched/scanned object without tracing it with vectors?

    Is it possible on illustrator or any other programs you know of?
    I've tried using the live paint bucket but it won't color in the sections the way I want. 
    It is a very complex sketch and it's going to take forever if I try to trace it all with vectors.

    This sounds like a job for Photoshop. It's a scan, and you don't want to turn it to vectors, so a vector program like Illustrator is not the best choice in this case.

  • Can we perform two actions with one button with two clicks one after other?

    Sir,
    can we perform two actions with one button with two clicks one after other?
    I want that when I click an Add Button first time it add data to the database and when I click again this button it clear the form data to empty fields.
    Regards
    Tanvir

    In code it should be easy.
    The following code adds a button called butman with a text "ADD".
    It then registers a listener that will be called if the button is clicked.
    This listener then calls the runAddData method if you clicked on butman while it contained the "ADD" text and it will call the runClearData method otherwise.
    Therefore it will swap the button's functionality between ADD and CLEAR on every click.
    final Button butman = new Button("ADD");
    butman.setOnAction(new EventHandler<ActionEvent>() {
              @Override
              public void handle(ActionEvent t) {
                        if (butman.getText().equals("ADD")) {
                                  butman.setText("CLEAR");
                                  runAddData();
                        } else {
                                  butman.setText("ADD");
                                  runClearData();
                        } // END IF-THEN
              }});I hope this is what you wanted.
    Some extra food for thought.
    You might want to run the ADD and CLEAR methods in their own threads so that it can run in the back ground, without slowing down your user interface.
    I also like to rather reuse one button for multiple functionality in stead of making an application with hundreds of nodes only used rarely with masses of code to show and hide them if needed.

  • Enlarged Smart Objects with vectors inside them appear as resized bitmaps

    In Photoshop CC for Mac I have...
    Created layers of vector art
    Combined them into a smart object
    Enlarged the smart object (both via "Transform" and "Image Size")
    Upon enlarging, the vector objects look the way an enlarged bitmap would (i.e. fuzzy, pixelated, terrible) instead of crisp and clean as a vector should look. I've double- and triple-checked to make sure all layers have remained vector after resizing and they have.
    This is a terrible inconvenience for anyone that works heavily with vector smart objects and resizes them. I use this workflow on a daily basis to make adapting interface elements for various screen resolutions easier, without it I am beyond screwed.
    If anyone knows a workaround (or if this requires a setting that I haven't found to be changed) please let me know.
    Screenshot proof below:

    Read this thread -link http://forums.adobe.com/message/3498406#3498406
    you may want to read it from the beginning.
    Basically while a smart object layer embedded object may contain  vector graphics.  Photoshop renders a composite for the embedded object and uses the resulting rendered pixels for the smart object layers pixels.  When you transform a smart object layer your transforming those pixels like raster layer using your Photoshop preference interpolation preference..  If you want to resize the vector graphics contained in the embedded object you must open the embedded object into the approbate application and resize the embedded object using vector tools. After you commit the resize. Photoshop will update the embedded object and the layers pixel will be the composite rendered for the updated resized embedded object.

  • Improving performance of query with View

    Hi ,
    I'm working on a stored procedure where certain records have to be eleminated , unfortunately tables involved in this exception query are present in a different database which will lead to performance issue. Is there any way in SQL Server to store this query
    in a view and store it's execution plan and make it work like sp.While I beleive it's kinda crazy thought but is there any better way to improve performance of query when accessed across databases.
    Thanks,
    Vishal.

    Do not try to solve problems that you have not yet confirmed to exist.  There is no general reason why a query (regardless of whether it involves a view) that refers to a table in a different database (NB - DATABASE not INSTANCE) will perform poorly. 
    As a suggestion, write a working query using a duplicate of the table in the current database.  Once it is working, then worry about performance.  Once that is working as efficiently as it can , change the query to use the "remote" table rather
    than the duplicate. Then determine if you have an issue.  If you cannot get the level of performance you desire with a local table, then you most likely have a much larger issue to address.  In that case, perhaps you need to change your perspective
    and approach to accomplishing your goal. 

  • Memory leak: critical (blocker) bug with unloading SWF with Vector. T

    Here's the original bugreport https://bugbase.adobe.com/index.cfm?event=bug&id=3071138
    dated december 2011 (add actually appeared even earlier). Despaired of getting any Adobe's team attention I even submitted it again today (as of new releases of FP 11.3 and AIR 3.3 betas).
    Chris Campbell, seems like u're active on this forums. Can you give any feedback?

    This bug has definitely been around a while.  The good news is that it's currently slated "Open / To Fix" for our AIR 3.3 release which is currently up on labs.adobe.com  (our internal number is 3072792).  We've been able to reproduce the problem and our development team is actively investigating.
    The best way to make sure this gets continued focus is to recommend to everyone you know who is affected by this bug to take a minute and cast their vote on the public bug.
    Bug 3071138 - Cannot unload (Loader.unloadAndStop) SWF with Vector.<T>

Maybe you are looking for