Array of vectors

if I have an array of vectors how would I got about add elements
to one of the vectors in the array, also how would I search a specific vectors object for equality on another object.
example: Vector [] lists = new Vector[61];
how would I add an ID object to on of the vectors.
also how would a search a vector for equality with a specific ID
object.
thanks

To add an object to (say) the 20th vector use
ID id = new ID();
lists.add(id);
Searching for equality is similar; use the contains method in the vector class.
I have not tried this, but it should work I think.

Similar Messages

  • Is there any way of  using arrays or vectors in JavaScript

    In my JSP page when ever a value in the text field changes i have to store that value before submitting a form. When ever the value in the text field changes i have to use "OnChange" option but i have to store all these values in an array or vector. Is there any other way of doing this. I am using webwork. Can any one help me!!!!!!

    JavaScript arrays are dynamic. You can add new values to the array and the array will grow in size.
    //a is an array of size zero
    var a = new Array();
    a[0] = "something";
    a[1] = "else";
    a[a.length] = "Adding another String at the end of my array";But here's something to think about. If your web site absolutely needs JavaScript, what happens to your site when the user decides to disable JavaScript in his browser....?
    I only use JavaScript to validate the user's input data, but I revalidate server-side in case JavaScript was disabled.

  • Please help, 2D Array of Vectors and Incompatible types :(

    I have a 2D array of vectors called nodeLocations but when I try and access the vector inside I get a compile error.
    My code is something like this:
    nodeLocations[j].addElement(noArc)
    My editor picks up that its a Vector and shows me addElement as an acceptable entry to put after the "." yet the compiler says:
    "addElement(java.lang.Object) in java.util.Vector cannot be applied to (int)"
    Can someone please help?
    Thank you in advance.
    also a related problem:
    I get inconvertible types (says int required) when I try and get an element from a vector stored in a 2D Array. I know that it comes out as an object and so should be cast but it does not seem to work. My code is as follows:
    else if (((int)(nodeLocations[nodeNumber][adjNodeNumber].elementAt(0))) != distance)
    I would appreciate any help anyone can give.
    Similar errors to the above two happen when
    I try a push with a Stack in a vector.
    I try to get something out of the stack inside the vector.

    The Vector class's addElement() method requires an Object parameter. It appears that you're trying to add an int to the Vector. You'll need to create an Integer object and place that into the vector (see sample below) or use the pre-release version of JDK 1.5 which provides autoboxing capabilities.
    int z = 5;
    Integer x = new Integer(z);
    nodeLocations[j].addElement(x);

  • How to create an array of Vectors ?

    Can I create an array of vectors in Java ? For instance I want to have an array of days in a year, an on each day there are several things to do, and I don't know this up front, so I want it to be a Vector holding the things_to_do object, some days might have nothing to do, so there should be null or an empty vector for that day. So I came up with something like the following :
    Vector<Things>[] Days_Array=new Vector<Things>[365];
    But Java doesn't allow this ?
    Frank

    Opps , I forgot to ask, although it compiled successfully, but it gave me a warning : [unchecked] unchecked conversion
    I wonder if there is a way to fix it without turning the warning off, what I meant is : Am I missing something that caused the warning that I should add to the code, I don't want to turn off the warning. For instance how can I make the "conversion" checked ?
    Frank

  • String[] array = (String[])vector.toArray();

    Why does the last line cause a ClassCastException?:
    Vector vector = new Vector();
    vector.add("One");
    vector.add("Two");
    vector.add("Three");
    vector.add("Four");
    vector.add("Five");
    String[] array = (String[])vector.toArray();
    Thanks
    [email protected]

    Because toArray () creates an Object array. You need the toArray(Object[]):String[] array = (String[]) vector.toArray (new String[vector.size ()]);Kind regards,
      Levi

  • Array or vector

    to store a list of alphanumeric strings, what would be the best way to store these, in an array or vector?
    could anyone help plz.
    thnks, lew

    You're welcome.
    If you declare your list this way:
    List myList = new ArrayList();Then you can change your mind and synchronize it later just by changing the right side to:
    List myList = Collections.synchronizedList(new ArrayList());If everything just expects a List, not necessarily an ArrayList, then you can change the type of List without ruining the rest of the code.

  • An array of vectors that contain a user defined class gives: warning: [unch

    I've read two tutorial on Generics and still don't get everything.
    Anyway I have a user defined class called a Part. I have some Vectors of Part objects, and these Vectors of Part objects are stored in an Array of Vectors.
    Amazingly, I got all the checking right so far; however, am now trying to loop through my Array, an pass the individual Vectors to a method:
    //create a single list of all parts numbers
    //add the part number from each vector/part into a new vector of strings
    for(int y=0; y < ArrayOfPartVectors.length; y++) {
        Vector<Part> vTemp = ArrayOfPartVectors[y];
        vAllPartNumbers.addAll(pm.getPartNumbersFromVector(vTemp));
    }I get the following warning:
    com\gdls\partMatrix\PartMatrix.java:75: warning: [unchecked] unchecked conversion
    found   : java.util.Vector
    required: java.util.Vector<com.gdls.partMatrix.Part>
                                    Vector<Part> vTemp = VectorArrayParts[y];
                                                                         ^
    1 warningNow I have put the 'check' (<Part>) in every concievable spot in that statement, and I get a compler error now instead of a warning.
    Any guidance would be appreciated.
    Thank you,

    The problem is not with Vector. If you want to use it that's fine.
    You could also want to use ArrayList because the class is roughly equivalent to Vector, except that it is unsynchronized.
    But your problem is that arrays and generics don't mix well as previously mentioned in the first reply.
    You did not specify the type of ArrayOfPartVectors but I guess it is Vector[], not Vector<Part>[], right?
    So you'll have an unchecked warning when doing the conversion from Vector to Vector<Part> in the assignment within the loop.
    Maybe you tried to use a ArrayOfPartVectors of type Vector<Part>[] instead but found it impossible to create it with new
    You can do it with Array.newinstance() but you'll get an unchecked warning at this line instead of later.
    So mixing generics and arrays will allways result in warnings.
    You should read: [url http://www.angelikalanger.com/Articles/Papers/JavaGenerics/ArraysInJavaGenerics.htm]Arrays in Java Generics.
    Regards

  • Size restrictions on arrays and vectors

    Hi all!!!
    I want to know whether there is any restriction on maximum size of array and vectors.
    If I have thousands of records to be displayed on browser through JSP, can I initialise the arrays/vectors with that no.
    Whether it will have adverse effect on performance.
    Thanks in anticipation

    Array lists (and vectors) use an array as backing data store. And since array indices are ints, the maximum number of elements in an array list is Integer.MAX_VALUE (2 ^ 31 - 1).
    About the performance: if you know how many elements you are going to add (albeit not precisely), you can create the array list with an initial capacity. This will improve performance because a new array is created when an element is to be added but the capacity has been reached.
    Kind regards,
      Levi

  • Use array or vector ?

    I need to store data into a 3D array i.e. abc[128][128][128]. Every item of the array is an object.
    My problem is, if i use 3D array to store the data directly, it is too memory costing and always return OutOfMemoryError!!! Also terribly slow !
    Is it better to use vector of vector instead of 3D array? I mean put the 128 objects into a single array and then put 128 single arrays into a vector, lastly put 128 vectors into a new vector.
    Or otherwise, who has any other good suggestions to store these 128*128*128 objects?

    However, that's small compared to the number ofdistinct objects in that space -- 128^3. So the number
    of objects taken up by the arrays or vectors, is less
    than 1% of the number of objects in the 3D space
    defined by the arrays or vectors.
    Sorry, I don't get what you mean ;)
    Yes, it is 1% of the number of objects in the 3D
    space, but you haven't calculate the 4 bytes int value
    used by the int value itself.We're not talking about ints though, are we? The question was about a 3D space of objects.
    So, if let say array Object definition uses 2 bytes,
    then the RAM needed will be:
    Object definition + int values
    ((128^2 + 128 + 1) * 2) + ((128^3) * 4)
    if you create int[128^3], you will only create:
    128^3 * 4Given that problem statement, the array object definitions take up 33026 bytes, whereas the int values take up 8388608. So the memory used by the array object definitions is still just 1% of the memory used. By switching to a 1D array of length 128^3, you're saving less than 1% of the memory. The 33026 bytes isn't the problem here.
    (((128^2 + 128 + 1) * 2) + ((128^3) * 4)) is a much bigger number than ((128^2 + 128 + 1) * 2).
    Just (128^3 * 4) is a much bigger number than ((128^2 + 128 + 1) * 2).
    But anyway that's not the problem statement anyway. There are 128^3 potential objects created in the heap. That's going to be a lot more than the arrays or vectors used to reference them.
    This is why I think the best solution is to look at the data and see if a better approach can be taken than just using 128^3 buckets.
    Another slow but possible solution is using HashMap.
    To check coordinate 33, 75, 109, you can use:
    map.get(new Integer(33*75*109)] and hope Java garbage
    collector runs pretty fast.I wouldn't advise that, because that would cause conflicts between objects at 33,75,109 and 75,33,109, etc. There would be 3! = 6 possible conflicts. If you want to turn the 3D index into a flat 1D index, then multiply each coordinate by a constant to put each into its own range, e.g., (33,75,109)'s 1D index would be (33 * (128^2)) + (75 * 128) + 109.
    Hopefully that's less than the maximum int value. It may not be.
    This solution works fine only if in vast 128*128*128,
    only few hundreds coordinate x,y,z which actually have
    a value. This way you can store the value only if
    needed.Yes, exactly, if the domain data is sparse, a different approach like this would work better than defining 128^3 data buckets.
    If the data is sparse enough, it might be easier to define a 3DCoordinate object to use as the index into the hashtable, than programmatically creating a 1D index.

  • Array in vector

    Hi
    I want to store an reusable array into vector, and access the array at a particular index of vector
    Vector v1 = new Vector();
    byte array[] = new byte[3];
    Array
    array[0] =1;
    array[1] =1;
    v1.addElement(Array);
    array[0] =3;
    array1] =3;
    v1.addElement(plArray);
    array = (byte[]) v1.elementAt(0);
    array = (byte[]) v1.elementAt(1);
    currently if i were to run this program, i will get 3,3,3 for both the v1.elementAt(0) and v1.elementAt(1), how sld i amend these codes so that I will get the correct results?
    Thanks

    Use a for loop that creates a new array each time:
    for(int i = 0;i<num_arrays;i++) {
        int[] a = new int[desired_length];
        //set the values of a here
        vector.add(a);
    }

  • Array to vector - isn't working.

    Hello all.
    Firstly, this is not a homework question. I am doing a course which teaches Object Oriented programming which happens to use Java to teach it. I've discovered I like programming in Java and figure I have just enough knowledge to be dangerous, so I have set out on a project of my own.
    The app I am building uses a webservice to log into a site and retrieve sports information, then performs calculations based on the information and sends further requests to get stuff done. Your basic webservice app I guess.
    The problem I am having at the moment is that I'm trying to populate a vector using a complex type array called EventType which is returned by the service.
    I'm not having any problems getting the information back from the service, but I want to use the data returned in a JTable, which means I have to construct a model for the table and it is here that I am striking my problem.
    I can access the EventType array and get the information from it easily enough and I can separate the information I want out of it pretty easily as well. What I am having trouble doing is putting the information into a collection of some sort which I can send to my AbstractTableModel.
    The EventType array contains four arrays of Strings and Integers. I only need to work with two of them though, so my first thought was to use a HashMap<Integer, String> because the integer will always be unique to that event and can be used as a key. Another way of doing it would be to pass the information over to the table model as a vector, then break it down in the model itself.
    I am having trouble iterating over the EventType array and inserting it into whatever collection type I am using though.
    Here is the code:
    // imports
    import com.betfair.publicapi.types.global.v3.EventType;
    import java.util.Vector;
    // declarations
    public static EventType[] sports;
    public static Vector sportsVector;
    // troublesome code
    sports = new EventType[result.getEventTypeItems().getEventType().size()];
    System.out.println("Number of sports: " + sports.length);
    sportsVector = new Vector();
    System.out.println("Made the vector...");
    for (int s = 0; s < sports.length; s++)
        System.out.println("Putting entry number " + s + " in now.");
        sportsVector.addElement(sports[s]);
        System.out.println("Added sport number " + s);
    System.out.println("Filled the map...");As you can see I have sprinkled the code with println's to track down where the problem is. The code works perfectly right up until I see:
    System.out.println("Putting entry number " + s + " in now."); the first time it goes through the loop.
    Whereupon the entire thing stops. There is no crash, there is no warning in the output window (I am using netbeans), nothing happens at all. The same thing happens when I try to use a Vector or a Set. I haven't tried a list yet.
    I'm fairly sure this is something basic I have missed, but I can't for the life of me figure out what it is.
    Any ideas please?
    Alan

    Thanks for your replies guys.
    I'm not sure what has happened there, since I didn't change anything except to restart netbeans (started to behave strangely), but suddenly it is filling the vector the way it is supposed to.
    I am getting a warning:
    Note: C:\Users\alan\Documents\NetBeansProjects\AnotherBF\src\anotherbf\SportsMonitor.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.Which I think has to do with declaring a type within the vector. I gave google a scouring and after trying the solution of declaring the type within the addElement method, the whole thing refused to compile.
    i.e.
    sportsVector.addElement(new EventType(sports[s]));I'm not sure how to fix that.
    Edited by: inksmithy on 23-Mar-2008 14:09 - saying thanks to people replying.

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

  • Arrays and vectors

    Hi
    I'm having a bit of difficulty with the following method
    I have a vector - numbera that is full of integers,
    What I want to do is copy these into in an array but I seem to be having a spot of bother getting this to work !!!
    When I try to print the contents of indexa I just get a null reference returned
    Can anyone help me out !!!
    public int[] indexa()
        int indexa[] = new int[numbera.size()];
        Iterator p = numbera.iterator();
        for (int i = 0; i < numbera.size(); i++)
          indexa[i] = Integer.parseInt(p.next().toString());
           return indexa;
    [\code]

    First,
    Did you fill the vector? What did you fill the vector with? Vectors cannot hold primitive data types (such as int). It always holds Objects, such as Integer. If you did all that already, there sould be stuff in the Vector, and it should not be null.
    Second,
    I don't like vectors, so I never use them. But when I do, I was taught to use Enumerations, not Iterators. Like so:
    Enumeration e = numbera.elements();
    int i = 0;
    while(e.hasMoreElements()){
       Integer elem = (Integer)e.nextElement(); //here i am assuming you put in an Integer
       indexa[i] = Integer.intValue(elem);
       i++;
    }I don't know how to use Iterators with vectors, since I've never done it that way. Maybe my solution is not what you are looking for, but I think it should work (provided I have made no typos).
    :) JenMc

  • JSP input fields  to be stored in an array or vector

    Hi:
    If I have '20' fields on a 'struts' form and I want each of those fields to be stored as elements of an array 'myArray'. How would you do it? Will the following works with reference to each element of the array?
    <tr>
    <td><html:text name="TestFormBean" property="myArray[0]" size="20"/></td>
    </tr>
    <tr>
    <td><html:text name="TestFormBean" property="myArray[1]" size="20"/></td>
    </tr>
    <tr>
    <td><html:text name="TestFormBean" property="myArray[2]" size="20"/></td>
    </tr>
    etc. etc.
    Thanks in advance!

    There's a customtag,iterator,which is to repeat every element of an collection.You'd better implement your form by this way since it's just provided by struts.:)

  • Array, continuous vector stream, manually updating

    Hello,
    I have got a continuous stream form a counter/timer card of an array. Now, when I press a button, I want to save the actuall values (x1, y1, z1) in another array. Pressing the button a second time, (x2, y2,z2) should be saved in this second array, so land until i stop the main loop manually.
    How can I realize that!
    Thanks.

    So, here is the problem again, with .vi. So, I am reading continuously an encoder, and want to write a set of data to file by pressing a button. For this, I use a Shift register, and case statement. But it is always replacing the column instead of appending, why? I mean, I think the 'false' case is responsible for that, because of the built array, but i am not sure. Someone might help me.
    Thank you guys.
    Attachments:
    test1.vi ‏45 KB

Maybe you are looking for