Vectors, lists, arrays

Hi, I'm writing a program using a variable length sequence of boolean values. I will want to manipulate this, altering & reading etc and don't know what will be most time efficient (prog has lots of iterations and takes a while). Any ideas what'd be best for this, vectors, lists, arrays or something else?
Cheers

There should be no difference.
For using List or any Collection interface, you need to use Boolean, the object though.
You can simplify the storage by just using boolean[], the array, but with "variable length", you have to deal with growing the array. So List is simpler overall.
--lichu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Passing values in a vector list as bind variables in sql query.

    Hi,
    I have a vector list containing values 12,13,14.
    vector<string> v;
    v has values 12,13 and 14.
    Here the number of values in vector list are not fixed.
    I want to pass these values as bind variables to sql query.
    Can anyone suggest me how to do this.
    Thanks in advance!!

    Ah, the it's the classic 'Varying In-List' again
    See:
    The Tom Kyte Blog: Varying in lists...
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:110612348061 (started more than a decade ago, so scroll down for more recent examples)

  • Modifying Vector List

    Hello,
    I have used AJAX to create a search list that is linked to a text box. So, as the user enters the a word in the text field then suggested matches are displayed below. The suggested matches come from a vector list. All of this works fine.
    I want to enhance this project a bit, I would like to turn the suggested matches from plain text into clickable hyperlinks. The idea is that these links will point to other jsp pages with the relavent info. I am having a bit of a problem doing this. Below is an extract of the vector list that displays all of the suggestions.
    private Vector<String> AnimalVector(Vector<String> dVector)
             dVector.addElement("Cow");
             dVector.addElement("Chicken");
             dVector.addElement("Sheep");
             dVector.addElement("Dog");
             dVector.addElement("Cat");
             return dVector;
         }    Is there a way I can make these plain text suggestions into clickable hyperlinks?
    Thanks.

    Thanks for the reply.
    I have decided to go for a Hashtable. Im not sure how to implement a Hashtable into the code I have. My understanding of a Hashtable would be something like
             Hashtable map = new Hashtable();
             map.put ("Cow", new String("www.microsoft.com"));
             map.put ("Sheep", new String("www.amazon.com"));
             map.put ("Dog", new String("www.yahoo.com"));Here is the full code, Im just not sure where I integrate a hashtable into this for the desired effect?
      import java.io.*;
      import javax.servlet.*;
      import javax.servlet.http.*;
      import java.util.Enumeration;
      import java.util.Hashtable;
      public class ajax extends HttpServlet {
         public void doGet(HttpServletRequest request, HttpServletResponse res)
         throws ServletException, IOException {
              Hashtable map = new Hashtable();
              res.setContentType("text/html");
             PrintWriter out = res.getWriter();
             String typed = request.getParameter("q").toLowerCase();
             String responsetext = new String("");
             for (Enumeration<String> e = map.elements() ; e.hasMoreElements() ;) {
                   String name = ((String) e.nextElement()).toLowerCase();
                   if (name.indexOf(typed)!=-1) {
                        responsetext = responsetext + name + "<br/>";
             out.println(responsetext);
             out.close();
             //Constructor goes here
             map.put ("Cow", new String("www.microsoft.com"));
             map.put ("Sheep", new String("www.amazon.com"));
             map.put ("Dog", new String("www.yahoo.com"));   
         }Many thanks.

  • Challeging Traversal of Vector and Array

    Hi there ! I would like to render the values of this Vector and Array . How do I print it out to the browser ?
    try
    ResultSet rset = stmt.executeQuery(myQuery);
    System.out.println(" Finish Execute Query !!! ");
    /* Array Contruction */
    int numColumns = rset.getMetaData().getColumnCount();
    while (rset.next())
    aRow = new String[numColumns];
    for (int i=0; i < numColumns; i++){
    aRow[i] = rset.getString(i+1);
    allRows.addElement(aRow);
    return allRows;
    }

    Hi there !
    Thanks for your help but I managed to get it working. For references purposes, I`ll post it here.
    My problem now is this :-
    How can I issue another SQL statement and store the results in the same array?
    Pls note . One Sql per table so, that`s the issue ?
    Can someone help with a followup code ?
    try
    ResultSet rset = stmt.executeQuery(myQuery);
    System.out.println(" Finish Execute Query !!! ");
    /* Array Contruction */
    int numColumns = rset.getMetaData().getColumnCount();
    while(rset.next())
    // for every record instance aRow
    aRow = new String[numColumns];
    // store in aRow the values of the record
    for(int i=0;i<numColumns;i++)
    aRow[i] = rset.getString(i+1);
    //When aRow is full store it in the vector
    allRows.addElement(aRow);
    // when the rset finished print all the Vector
    for(int i=0;i<allRows.size();i++)
    // get returns a String[]
    String[] tmpRow = (String[])allRows.get(i);
    for(int j=0;j<tmpRow.length;j++)
    out.print(tmpRow[j]+" ");
    out.println("");
    }

  • WHY WE USE VECTOR NOT ARRAY STRING

    Hi
    I want to know why we use Vector not bufferstring.
    What is the difference Vector(1,1) and STRING[1][1]?
    Which one we will prefer?
    Why we will prefer one of them?
    Please help me to find out.

    There are huge differences between array and Vector.
    Array is a special class that allows to keep references to a number of Objects of some type. It has a maximum length set during construction, and does not offer any methods to change it's size (without defining a new array).
    Vector is a class (thread-safe unlike it's new version ArrayList) that allows to keep references to any Object (may be of different types). It doesn't have a maximum length set, and can be potentionally of any size. It allows to easily remove, add, insert new elements and keeps all the elements in the order they were added (unless some object was inserted). This is a really well written class, and I'm always using it for storing some objects.
    Hope it was helpful.

  • Export as simple vector list

    I am trying to figure out how to get a simple list of the vectors in my file. (I need the information for use in a very old vector-editing program; it's a long story.) I know that EPS and SVG files have a vector list somewhere, but the file formats are so verbose, I can't figure out where it would be. I would be happy with a list like:
    65 172
    100 -28
    102 -47
    101 -57
    99 -63
    That sort of list is really what I need... Any help would be really appreciated. Thanks.
    Jeff

    Fairly easy ?
    Extracting all vectors in a PostScript file and converting
    them into one coordinate system requires a PostScript
    interpreter which understands the majority of the keywords
    below (taken from PSAlter for PS2), which appear in AI EPS
    files not literally but by (cascaded) abbreviations:
    scale, rotate, translate, matrix, setmatrix,
    initmatrix, defaultmatrix, identmatrix, currentmatrix, concatmatrix,
    concat, transform, itransform, dtransform, idtransform, invertmatrix.
    Graphics state operators: gsave, grestore, grestoreall, initgraphics,
    gstate, setgstate, currentgstate.
    moveto, rmoveto, lineto, rlineto, curveto,
    rcurveto, arc, arcn, arcto, arct, closepath, newpath, flattenpath,
    reversepath, currentpoint, pathbbox, pathforall.
    User paths: uappend, ufill, ueofill, ustroke, ustrokepath, upath,
    ucache, setbbox, ucachestatus, setucacheparams.
    setgray, currentgray, setrgbcolor,
    currentrgbcolor, sethsbcolor, currenthsbcolor, setcmykcolor,
    currentcmykcolor, setcolorspace, currentcolorspace, setcolor,
    currentcolor, makepattern, setpattern.
    fill, eofill, clip, eoclip, clippath, initclip, rectfill,
    rectstroke, rectclip, image, imagemask, colorimage, execform.
    infill, ineofill, instroke, inufill, inueofill, inustroke.
    stroke, strokepath, setlinewidth, currentlinewidth, setlinecap,
    currentlinecap, setlinejoin, currentlinejoin,
    setmiterlimit, currentmiterlimit, setdash,currentdash,setstroke-
    adjust, currentstrokeadjust.
    findfont, scalefont, makefont, setfont, selectfont, definefont,
    undefinefont, currentfont, rootfont, setcachedevice, setcache-
    device2, setcharwidth, StandardEncoding, ISOLatin1Encoding,
    findencoding, FontDirectory, GlobalFontDirectory, SharedFontDirectory, cachestatus, setcachelimit, currentcache-
    params, setcacheparams, eexec.
    show, ashow, widthshow, awidthshow, kshow, stringwidth, charpath,
    xshow, xyshow, yshow, glyphshow, cshow.
    Furtheron, all paths have to 'flattened' (converted into poly-
    lines; for example Bézier paths or arcs).
    Rect.. has to be converted into single vectors, and so on (and so
    on, for instance handling line caps and miters).
    Converting into one coordinate system requires: transform with
    respect to 'currentmatrix'.
    Best regards --Gernot Hoffmann

  • Add vector list to a default list model

    Hello can someone please tell me how to add a vector list to a defaultlistmodel

    1) You've already been told that Swing related questions should be posted in the Swing forum.
    2) You where already given the answer to this in your last posting on the topic.
    So quit wasting peoples time by posting unnecessary questions.

  • [svn:osmf:] 11069: Minor API change: Use Vector not Array for MediaElement. get traitTypes.

    Revision: 11069
    Author:   [email protected]
    Date:     2009-10-21 16:52:10 -0700 (Wed, 21 Oct 2009)
    Log Message:
    Minor API change: Use Vector not Array for MediaElement.get traitTypes.  Approved by dev team. Should be no impact to sample apps, unit tests, or test apps.
    Modified Paths:
        osmf/trunk/framework/MediaFramework/org/osmf/media/MediaElement.as
        osmf/trunk/framework/MediaFramework/org/osmf/proxies/ProxyElement.as

    Revision: 11069
    Author:   [email protected]
    Date:     2009-10-21 16:52:10 -0700 (Wed, 21 Oct 2009)
    Log Message:
    Minor API change: Use Vector not Array for MediaElement.get traitTypes.  Approved by dev team. Should be no impact to sample apps, unit tests, or test apps.
    Modified Paths:
        osmf/trunk/framework/MediaFramework/org/osmf/media/MediaElement.as
        osmf/trunk/framework/MediaFramework/org/osmf/proxies/ProxyElement.as

  • Vector  or Array List better usage

    Hi form
    For storage of large Object's Which is a better management API
    Vector OR ArrayList
    Please some one Enlightern me
    with regards
    Karthik

    Please some one Enlightern meObjects in Java are always handled using references (pointers) to the actual object values (which reside on the so called heap).
    So from the point of the size of the objects, Vector and ArrayList are equivalent. No object values are stored in them, only references to objects and references always have the same size.

  • Problem in converting vector to array of strings

    hi
    i am having a vector which in turn contains hashtable as elements
    Vector v=new Vector()
    Hashtable ht=new Hashtable();
    v.add(ht.add("key1",value1))
    v.add(ht.add("key2",value2))
    v.add(ht.add("key3",value3))
    v.add(ht.add("key4",value4))now i am trying to conver this vector in to a array of string like
    String[] str=(String[])v.toArray(new String[v.size()]);but i am getting java.lang.ArrayStoreExceptioncan anybody help me plz
    Thanks

    Hi,
    The api for public Object[] toArray(Object[] a) says
    Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array.
    ArrayStoreException will be thrown if the runtime type of a is not a supertype of the runtime type of every element in this Vector.
    The runtime type of the elements of the vector is Hashtable.
    Because String is not a supertype of Hashtable the ArrayStoreException is thrown.

  • How to create a list/array off numbers with boolean attributes

    Hi,
         Maybe the title doesn't explain this too well but what I'm trying to do I'd imagine should be straight forward, I just don't know how!
    I want an array of numbers to be entered by a user, and for each of these numbers I wish to have a boolean, (it will select later what action is performed on that number)
    The array size can vary
    e.g.
    element       Numeric Value              Boolean
    0                       5                             True
    1                       20                           True
    2                       -5                            False
    3                       10                           True
    n                       100                         False
    I don't see any list with numeric and boolean, maybe I just haven't spotted it or do I have to make it somehow?
    Any suggestions please?
    Thanks!
     p.s. if anyone else is using Opera Browser to post here, hitting enter work properly for ye when entering text? For me it causes the cursor to go up one line instead of down! Drives me nuts! It only happens with this NI forum
    Solved!
    Go to Solution.

    Hi thanks for the reply, 
                              It not really what I'm looking for though. 
    I require is a control that inputs both numeric and boolean,  as in the example I mentioned. I guess I'm looking for a cluster really but I thought there may be something more straight forward.
    From the example I gave  
    Element 0 of this array has been entered as a x, and the boolean True was entered (so I perform a "test" A on value x)
    Element 1 of this array has been entered as a y, and the boolean True was entered (so I perform a "test" A on value y)
    Element 2 of this array has been entered as a z, and the boolean False was entered (so I perform a "test" B on value z)
    I could also use a 2d array were I enter another numeric value (0/1 for False/True) but I'm not sure I can limit this column only to accept 0 or zero and the first row any number.
    I was hoping there would be some easier way to do this

  • Newbie question about using vectors and arrays

    I'm fairly new to JME development and java in general. I need some help in regards to Vectors and 1 dimensional arrays. I'm developing a blackberry midlet and am saving the queried info i pull back from my server side application with each record saved into the array and subsequently each array saved as an element in the vector, thereby creating a 2D "array".
    However I'm having a problem accessing the elements in the array. Here is a sample of what I mean and where I get stuck:
    Vector _dataTable = new Vector(1, 1);
    String[] r1 = {"a", "b", "c", "d"};
    String[] r2 = {"1", "2", "3", "4"};
    _dataTable.addElement(r1);
    _dataTable.addElement(r2);
    Object temp = _dataTable.elementAt(0); //Save the element as an new object for useNow how do I access the particular indexes of the element of the temp object? Do i need to caste it to an array? Is there another more efficient/easier way I should be storing my data? Any help would be great!
    Edited by: Sotnem2k1 on Apr 1, 2008 7:50 AM
    Edited by: Sotnem2k1 on Apr 1, 2008 7:51 AM

    Thanks for the feedback newark. I have this scenario below:
    // Class for my 1D array
    public class OneRecord {
        private String[] elementData = new String[4];
        public OneRecord() {   
            elementData[0] = null;
            elementData[1] = null;
            elementData[2] = null;
            elementData[3] = null;
        public OneRecord(String v1, String v2, String v3, String v4) {   
            elementData[0] = v1;
            elementData[1] = v2;
            elementData[2] = v3;
            elementData[3] = v4;
        public void setElement(int index, String Data) {
            elementData[index] = Data;
        public String getElement(int index) {
            return elementData[index];
    } Then in my main app I have:
    Vector _dataTable = new Vector(1, 1);
    OneRecord currRecord = new OneRecord("a", "b", "c", "d");
    _dataTable.addElement(currRecord);
    OneRecord temp = (OneRecord)_dataTable.elementAt(1);
    System.out.println(temp.getElement(0)); Are there more efficient data structures out there to save queried data from a server side app? Like I said, i'm still trying to learn the most efficient techniques of coding...esp for the Blackberry. Any suggestions would be great!

  • Passing dynamic list / array of values to Droplet

    I want to know what's the best way to pass list of values as array or list to a droplet.
    Any examples here?

    u can refer to the following droplet , it uses both list and array
    <droplet bean="/atg/commerce/pricing/PriceEachItem">
    <param name="items" value="param:product.childSKUs">
    <!-- the product param is already defined in this scope so we do not need to set it -->
    <oparam name="output">
      <!-- Now iterate over each of the CommerceItems to display the prices -->
      <droplet bean="/atg/dynamo/droplet/ForEach">
      <param name="array" value="param:element">
      <param name="elementName" value="pricedItem">
      <oparam name="output">
      <valueof param="pricedItem.auxiliaryData.catalogRef.displayName"></valueof> -
      <!-- Toggle a different display depending if the item is on sale or not -->
      <droplet bean="Switch">
      <param name="value" value="param:pricedItem.priceInfo.onSale">
      <oparam name="false">
      <valueof param="pricedItem.priceInfo.amount" currency>no price</valueof>
      </oparam>
      <oparam name="true">
      List price for <valueof param="pricedItem.priceInfo.listPrice" currency>no price</valueof>
      on sale for <valueof param="pricedItem.priceInfo.salePrice" currency></valueof>!
      </oparam>
      </droplet><BR>
      </oparam> 
      </droplet>
    </oparam>
    </droplet>

  • Labview vi that takes data and populates a list/array

    Hello everyone, I was assigned to create a device that acquires voltages. I found a Data Acquisition box that does just that (not from NI, so I had to use activeX).
    Although I am only electrical, and don't have too much experience with programming, I tried a VI that could capture this data.
    The following is something that works but does not do exactly what I need. It only acquires the data for a specific channel selected manually using a numeric control and displays it on "data" digital indicator. What I have been trying to do is do the channel change automatically, starting from channel 0 to 6 (increment by 1), and each time populating some kind of array or list with this value until all 7 readings are taken. I tried For Loop, which seems easier to use, with a zero as a starting constant, but as hard as I try, it won't work. I would appreciate any help on the matter.

    joshorola wrote:
    Hello everyone, I was assigned to create a device that acquires voltages. I found a Data Acquisition box that does just that (not from NI, so I had to use activeX).
    Although I am only electrical, and don't have too much experience with programming, I tried a VI that could capture this data.
    The following is something that works but does not do exactly what I need. It only acquires the data for a specific channel selected manually using a numeric control and displays it on "data" digital indicator. What I have been trying to do is do the channel change automatically, starting from channel 0 to 6 (increment by 1), and each time populating some kind of array or list with this value until all 7 readings are taken. I tried For Loop, which seems easier to use, with a zero as a starting constant, but as hard as I try, it won't work. I would appreciate any help on the matter.
    Your image is pretty useless, because we cannot see most of the code (It is hidden in other frames of the stacked sequence structure!) The use of stacked sequences typically is discouraged. Don't use them!
    Also your while loop is unecessary, because it only iterates once. If you would remove the while loop, nothing would change.
    Since you know the number of channels (and thus iterations) before the loop starts, a FOR loop is correct. We cannot tell what you did wrong unless you show us what you tried.
    Please attach your actual VI. Thanks
    LabVIEW Champion . Do more with less code and in less time .

  • Copy the values of Vector to Array

    hi all,
    I have one problem that is
    I have one vector that holding objects (Ovalue)
    and Ovalue has the x,y values....
    I would like to copy the x,y values to one array
    if anyone knowd please help me
    thanks..

    Vectors have a toArray() function.

Maybe you are looking for