Two Dimensional Vector ?

Hya,
Is it possible to have two dimensional Vectors ?
if yes, how would be declared ?
I have a class called pencil,
I want to put each 12 pencils in 1 Vector (pencil box)
then add each of those vectors into a vector (box of pencil boxes)
thanks in advance

There's not really any such thing as a 2D vector
(unless you create such a class) but you can create a
Vector of Vectors. You can just add pencils to
vector and add that vector to another vector.
You might want to consider creating a PencilBox
class, rather than using a Vector to hold the
pencils.
You should also use ArrayList rather than Vector.When should an arrayList be used ? or when should a Vector be used?
thanks

Similar Messages

  • How to change the value of a two dimensional vector

    hi,
    I have a two dimensional array, Vector<Vector> myData, which contains strings. It's size is 5 rows and 6 columns
    I would like to change the value of, say, row 3, colum 5 from whatever it contains now to "new data"? I have searched and searched, but no luck
    thanks

    micheleg wrote:
    hi,
    I have a two dimensional array, Vector<Vector> myData, which contains strings. It's size is 5 rows and 6 columns
    I would like to change the value of, say, row 3, colum 5 from whatever it contains now to "new data"? I have searched and searched, but no luck
    thanksFirst off, you do not have an array of any dimension.You have a Vector that contains Vectors that contain Objects (you should provide a more specific type in your declaration).
    To change the element at position x in the y'th Vector, get the y'th Vector and change the x'th element in said Vector.
    As a side note, you should be using ArrayList instead of Vector these days.

  • Problem with two dimensional Vector

    It is better to use one dimensional array stored in Vector
    or use Vector stored in Vector?

    nwoedf wrote:
    It is better to use one dimensional array stored in Vector
    or use Vector stored in Vector?It's better not to use Vector at all, but rather to use a class from Collections such as ArrayList.
    As to the question of what to nest in what, I think that this depends on what you are doing with this data structure, how you're using it. For instance in many situations it's often better to nest a non-array/collection object in an arraylist rather than an array or another collection.

  • Two dimensional Grouping

    Hi 2 all,
    I'm trying to build a report starting from two complex PL/SQL query like this(simplified):
    SELECT SUM(x),SUM(y),SUM(z),Name,type,product
    FROM DESC A, STORE1 B, STORE2 C, store3 D, store4 E
    WHERE b.ID=c.ID(+)
    AND b.ID=d.ID(+)
    AND b.ID=e.ID(+)
    AND a.code=b.code
    AND a.product='oneproduct'(...another query with !='oneproduct')
    group by b.Name,b.type
    I need to have on each report page the results of the two queries grouped by type, one page for each (Name).
    how can I have the content of Name field on the header/margin (as a title) and the remainder data below grouped by the same Name?
    =&gt; In the end I should have one page for each Name
    thanks
    Matteo

    On the other hand I do recall having read somewhere
    that the "new" operator
    is very costly and should strictly be
    avoided in loops.Not that expensive performance-wise. It could potentially suck up a lot of memory if you are creating LOTS of objects
    Now for the concrete case of reading some user's
    datasets from a database
    and then processing them further, is it advisable
    to instantiate a new user object for each row, or
    where is the alternative
    to be found?I think you should create an object to represent each row.
    two dimensional collections (any favourites in java)I always create my own. I try to use Vectors and Hashtables exclusively, depending on my needs re: ordering and lookup. Mixing and matching these could result in Vectors of Hashtables, Vectors of Vectors, Hashtables of Vectors, and Hashtables of Hashtables.
    synchronized one dimensional collections each
    representing one field in a
    table ? (is this really more performant than simple
    classes)Doubtful - any gain that you get by avoiding the constructor call would be obviated by the overhead of iterating through multiple lists and keeping them synchronized.
    a Collection of Collections (here comes the new
    operator again)Same as two-dimensional collections.
    I remember having seen inner classes used for the
    purpose of holding just a
    couple of attributes, is there some performance
    advantage like "the class
    loader does not have to look for the class".No advantage - the only reason to create an inner class is to prevent other classes from using those objects. The inner class still compiles to a separate class object that needs to be loaded separately.

  • Return a two dimensional array

    Hi,
    I'm probably doing this wrong from the start, but I have an two dimensional array with only integers. These are the result of some mathematical calculations (aren't they always? :-) ) and I need to use those in another class. So I placed this array in a Vector and used this as a return value.
    It looks like this:
    final int[][] somArray = new int[aantalSommen][3];
    Vector maalSommen= new Vector();
    somArray[counter][0] =A;
    somArray[counter][1] =B;
    maalSommen.add(somArray[counter]);
    return maalSommen;So now I have this array into a vector, I can't get the values out.
    in the code below Vector sommen is the vector containing the array.
    for (int i =0;i<sommen.size(); i++ ) {
      int [][] som=(int[][]) sommen.elementAt(i);
    }The above code is not working.It gives me a cast error..

    ok, this is my attempt for the sscce...
    This class generates the results I need..
    public Vector MaalSommen(int aantalSommen, int[] TafelReeks) {
              final Vector maalSommen = new Vector();
              final int[][] somArray = new int[aantalSommen][3];
              boolean dupesCheck=false;
              int A = 1;
              int B=1;
              for (int counter=0; counter<aantalSommen; counter++) {
                   A=generator.nextInt(10);
                   B=randomizeArray(TafelReeks);
                   // check for dupes..
                   while ( ! dupesCheck) {
                        if (!( dupesCheck=checkDupes(A,B, counter,somArray))) {
                             A=generator.nextInt(10);
                             B=randomizeArray(TafelReeks);
                   dupesCheck=false;// reset the checker
                   somArray[counter][0] =A;
                   somArray[counter][1] =B;
                   somArray[counter][2] =somArray[counter][0]* somArray[counter][1];
                       maalSommen.add(somArray[counter]);
              return maalSommen;
         }What I think is happening is I put the array into the vector..But it turn out this is not the case..

  • Please change the view in the top sites, the 6.1 upgrade has reverted back to a plane two dimensional view, which is a little plain. Can I revert back to an older version via my time capsule save?

    Please change the view in the top sites, the 6.1 upgrade has reverted back to a plain two-dimensional view, which is a little dated. Can I revert back to an older version via my time capsule save? C'mon Apple upgrades supposed to leap into the future not the past. :-(

    Please change the view in the top sites, the 6.1 upgrade has reverted back to a plain two-dimensional view, which is a little dated. Can I revert back to an older version via my time capsule save? C'mon Apple upgrades supposed to leap into the future not the past. :-(

  • How to get number of rows and columns in a two dimensional array ?

    Hello,
    What would be the simplest way to get number of rows and columns in a two dimensional array represented as integers ?
    I'm looking for another solution as For...Each loop in case of large arrays.
    Regards,
    Petri

    Hi Petri,
    See a attached txt file for obtaining two arrays with upper and lower index values
    Regards
    Ray
    Regards
    Ray Farmer
    Attachments:
    Get2DArrayIndex.txt ‏2 KB

  • Create a two dimensional table in Acess

    Hi,
    I am working with a database and the toolkit "the database connectivity tooset". I know how to create a new table from labview, but is it possible to create a "two dimensional" table from labview, i.e, where one table in Microsoft Access is linked to another one. I know how to do it in access, but it should be possible in program to crate a new table and this one has to be linked to another one then, just like the others. Does someone know how to do it??
    Thank you!

    Hi
    I assume you are not so familiar with databases, are you?
    First I want to comment your previous post:
    well I have a table for a product that contains, say different data for the product, i.e. the date of the test, who is responsible for the test, where it was performed. Also, linked to the date (I guess it is the primary key), there are also some data related. so in my table in the database, next to the date, there is a "+"-sign, so I can open up the page of all the data related to the date.
    Well, did you create this database on your own? So you must have created two tables (table one with fields Datum, Responsible & Cost and table two with fields Place1, Place2, Place3 & Place4). Then you must have dragged on field from one table to another field in the other table in the "Relations" view of access. Doing so, you created a relation. Due to this, access now knows how this date is related and displays the "+"-sign. You can not assume that the date is the primary key.
    In fact you do not have a "2D" table, but just different datasets from two tables connected to each other. This connection is created by relations.
    So, if I know would like to create a new table in my program (each product has its own table, so a new product=a new table), I would also like to create this "data" sheet that is connected to the data. Bu how do I do that?
    I can easily just create a new table (i.e. a new product), just using the "DB Tools Create Table.vi". But I guess it is when I actually want to add the data to the database, where I create the "data" sheet? Using the "DB Tools Execute Query" and a SQL statement with INSERT INTO, is that the way to go?
    As mentioned before, this "datasheet" is just a dataset from a second table which is made displayable by the relation. So if you're question is "how to create a relation using LV", you are quite on the right way. First create two tables one of which has to contain a field where the primary key from the other table is linked to. Then you have to set a PK in one table (using SQL statements) and then build the relation (also using SQL statements). I can't tell you, if you have to define the foreign key in the second table too.
    Have a look at the MS-Access help on how to assign relations and how to define primary keys. There may be something to take care off. Basically standard SQL should do - but using MS you never know .
    As this is somehow complicated, I always create the database structure in MS Access and that's it - afterwards all is done programatically (write and read data). Usually I don't open the database again with Access unless there is a special task.
    Hope this helps you a little bit otherwise come and ask again.
    Thomas
    Using LV8.0
    Don't be afraid to rate a good answer...

  • How to copy data in text file into two-dimensional arrays?

    Greeting. Can somebody teach me how to copy the input file into two-dimensional arrays? I'm stuck in making a matrix with number ROWS and COLUMNS according to the data in "input.txt"
    import java.io.*;
    import java.util.*;
    public class array
        public static void main (String[] args) throws FileNotFoundException
        { Scanner sc = new Scanner (new FileReader("input.txt"));
            PrintWriter outfile = new PrintWriter("output.txt");
        int[][]matrix = new int[ROWS][COLUMNS];
    }my input.txt :
    a,b,c
    2,2,1
    1,1,1
    2,2,1
    3,3,1
    4,4,1
    5,5,1
    1,6,2
    2,7,2
    3,8,2
    4,9,2
    5,10,2

    import java.io.*;
    import java.util.*;
    public class array {
        public static void main(String[] args) throws IOException {
            FileInputStream in = null;
            FileOutputStream out = null;
    try {
        in = new FileInputStream("input.txt");
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            String split[]=line.split(",");
    catch (IOException x) {
        System.err.println(x);
    } finally {
        if (in != null) in.close();
    }}}What after this?

  • How to use two dimensional array in custom.pll

    HI
    How to use two dimensional arrays in custom.pll
    I tried by the following way .
    type ship_array is table of number index by binary_integer;
    type vc_array is table of ship_array index by binary_integer;
    But I am getting the error as that
    A plsql table may not contain a table or a record with composite fields.
    Please tell me the way how to use them

    which forms version are you using? two dimensional arrays are available in >= 9i if memory serves.
    regards

  • Variable number of two dimensional arrays into one big array

    I have a variable number of two dimensional arrays.
    The first dimension is variable, the second dimension is always 7.
    i.e.:
    Object[][] array0 = {
    {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
    {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
    Object[][] array1 = {
    {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
    {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
    Object[][] arrayi = ...I'm generating these arrays with a for-loop:
         for (int i = 0; i < filter.length; i++) {
              MyClass c = new MyClass(filter);
              //data = c.getData();
    Where "filter" is another array which is filled with information that tells "MyClass" how to fill the arrays.
    "getData()" gives back one of the i number of arrays.
    Now I just need to have everything in one big two dimensional array.
    i.e.:Object[][] arrayComplete = {
    {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"},
    {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"},
    {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"},
    {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"},
    Any idea on how to accomplish this? It's blowing my mind right now.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Just brainstorming here:
    Why not put your actual data in a class and store that in a LinkedList (so you know the total number of elements for your multi-dimensional array). Then initalize your multi-dimensional array and populate it? Haven't tested the following, but thinking something along the lines of
    public class MyData {
         //data here
         public Object[] toArray() {
              //something similar to this
              return new Object[] = {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"};
    LinkedList<MyData> data = new LinkedList<MyData>();
    data.add(mydata1);
    //however many times you need
    Object[][] arrayComplete = new Object[data.size()][7];
    for(int i = 0; i < data.size(); i++) {
         arrayComplete[i] = data.removeFirst().toArray();
    }Another option for knowing how many rows you would need might be using something like:
    int rows = 0;
    rows += array1.length;
    rows += array2.length;
    //etc...But is not entirely useful if you don't know how many variable arrays you have (although reflections might help if the name of the array variable is incremented systematically, someone told me earlier to avoid reflections since it could make debugging a LOT more difficult).
    Edited by: bogdana on Apr 1, 2010 10:38 AM

  • Retrieving  two dimensional arrays from a text file.

    Good evening
    I am having a problem with reading a text file, and putting this info into a 2D array to be put into a table.
    I have the table already(but no code to add rows to the table incase the array increases)
    The array is called Product[a][ b ]
    where a is the product number(the row), and b are details about this product.
    The file i want to be read looks like this:
    data.txt
    CPU|AMD|X2, 64bit, 2GHz|$150|9
    Video card|NVidia|7800 GTX 256MB|$400|4
    e.g. product[2][4] would equal 4
    Basically: Type, manufacturer, specifications, price, amount in stock.
    the "splitter" or "field terminator" is "|"
    This is what i want it to do:
    Store fileline into single string,
    split string and put it in product[ j ][ i ]
    repeat with next lines until nothing is read anymore.
    This is the code I have so far:
    try{
            FileReader textFileReader = new FileReader("C://BACKUP2//data.txt");
            BufferedReader textReader = new BufferedReader(textFileReader);
            for(int j=0; j<0; j++){
                 for(int i=0; i<6; i++){ //i starts at 0, condition: i is under 6, 1 is added to i at each loop/update.             
                       ProductT = textReader.readLine();
                       textReader.close();
                       for(String Product[j] : ProductT.split("|")){ //this line is completly wrong, but i don't know how else to do it.
         // for counting for the number of columns
    catch (IOException e) {System.out.println(e);}
    I don't even think this code makes any bloody sense, I don't know if I'm approaching it correctly.
    Would anyone be gracious enough to give me a helping hand and tell me what/how to change my code?
    from what I see, the problem lies less in the loops, but more in the splitting of the string. no function seems to like 2D arrays :(

    So this is where I stand:
         //Reading
        try{
            FileReader textFileReader = new FileReader("C://BACKUP2//data.txt");
            BufferedReader textReader = new BufferedReader(textFileReader);
            for(int j=0; j>0; j++){ // this will go on forever now or what?
    // yes, this will loop forever, which is fine as long as you break out of the loop when you reach the end of the file (which is indicated by textReader.readLine() returning null)
                 // replace the for(String currentField : ProductT.split("|")) loop with this one
                 //for(int i=0; i<6; i++){ //i starts at 0, condition: i is under 6, 1 is added to i at update.       
                      String inputline = textReader.readLine();    // read a single line from the file each time through the loop
                      //while (inputline != null) {
                            if (inputline != null) {    // check if the end of the file has been reached
                           //ProductT = textReader.readLine(); //put to single string
                       //textReader.close(); //shut it off    // move this line to the end of processing, you don't want to close the file until you've read everything from it.
                       //for(String currentField : ProductT.split("|")){   //Split string...      according to JBuilder "The local variable currentField is never read"
                             // switch this loop to use the regular for(  ;  ;  ) type, that way you will have another counter to use as the second index in the product assignment
                                         //currentField = Product[j];
                        product[i][] = currentField; // use the index of the second loop as the second index here
    else {
    break; // break out of the loop when end of file is reached
         //} // the for i etc. end here
    } // End for j et cetera...
         } //end Try
    catch (IOException e) {System.out.println(e);}
    //cut the crap
    // close the reader here
    ok - so I am not quite sure about what you mean here
    "Assign each of the 5 fields to the five [][j]
    positions of the array. "
    should i put 5 "fors" in there? - currently the
    program is compiling - although they do not appear in
    the table.I put comments in the code that should answer those questions.
    The code for the table is
    Object[][] data = {
              {Product[0][0], Product[0][1],
                   Product[0][2], Product[0][3], Product[0][4]},
                   {Product[1][0], Product[1][1],
    Product[1][2], Product[1][3],
    uct[1][3], Product[1][4]},
                          {Product[2][0], Product[2][1],
    Product[2][2], Product[2][3],
    ct[2][3], Product[2][4]},
                              {Product[3][0], Product[3][1],
    Product[3][2],
    Product[3][2], Product[3][3], Product[3][4]},
                    {Product[4][0], Product[4][1],
    Product[4][2],
    Product[4][2], Product[4][3], Product[4][4]},
    ;If I do not declare any of these strings (e.g. I have
    only declared Product[0-2][] oldschol style) an error
    occurs, telling me that
    Caused by:
    java.lang.ArrayIndexOutOfBoundsException: 3
         at data.<init>(data.java:112)
         ... 5 more
    When you declare product, you'll need to give it a size for both dimensions. The first dimension will be the number of lines to be read from the file. You'll need to know this before allocating the array, so either count them in the file, (if that's good enough for this assignment) or loop through the file once before reading it to count the lines. The second dimension of the array will be 5, since that's how many fields each line has.
    btw; do I give those duke stars when all problems of
    my life(currently: reading the two dimensional
    string) have been resolved?I don't know about [i]all the problems of your life, but when the topic of the thread has been solved, then give them to whoever helped. :)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Formatting a two-dimensional list...

    Is there a way to create a two-dimensional ArrayList of Integers with all cells containing certain values, for example zeros? -I will be storing changing Integer values in certain x- and y-coordinates!!
    Something like:
    ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();But my problem is that the .get commands cause an Exception if a cell value is not set:
    list.get(x).get(y) and list.get(x).set(y,int)How could I get around the "null" values without Exceptions? Would you first replace the null values with zeros? (Or is there some other way to store such information?)

    If you want to a fill a List up with values, use java.util.Collections.fill().
    But do you really want it full of some kind of value, or do you just want to indicate "no value filled in" for a bunch of positions in the grid? What percentage of positions will not be filled in, or will be filled in with the default?
    Here's a simple sparse grid:
    public class Pair {
      final int x;
      final int y;
      public boolean equals(Object o) {
        Pair p = (Pair) o;
        return p.x == x && p.y == y;
      public int hashcode() {
        return x + y;
    public class SparseGrid {
      private Map<Pair, Integer> grid = new HashMap<Pair, Integer>();
      public Integer get(Pair p) {
        Integer i = grid.get(p);
        if (i == null)
          return 42; // the default.  or just skip this test if you don't want a default
        return i;
      // also a put method, left as exercise
    }That's all untested.

  • Problem returning a two-dimensional array in web service

    Hello. I'm having problems returning a two dimensional array in my web service. The service returns a MyClass[][] correctly, but the client receives a different one.
    I've done a test that returns a MyClass[1][1] an the client shows a MyClass[1][20]. All the MyClass objects returned in the array are the same and all it's fields are null. There's even an element of the array containing null instead of the object. As I say, the service creates the array ok, but the client gets other thing.
    I have other methods returning one-dimensional arrays MyClass[] and I have no problem.
    My system:
    WindowsXP
    Tomcat 5.5 (Axis 1.3?)
    JDK 1.5
    Eclipse 3.3
    My wsdl is generated with eclipse, although I've had to update my wsdd manually.
    Any Ideas?
    Thanks.

    Does it have to be stored in an array?
    Because you could use the java.awt.Point class, and a
    java.util.Set to create random points until you have
    the correct number of unique points.Of course it is no must to store it in an array. it was just my first thought of approaching the problem. I will try the Point.class. Thanks for that hint.

  • Mapping question - one dimensional to two dimensional

    Hi
       We are on XI 3.0 SP13 - and I have this mapping scenario
    Source structure - Linear & simple with say 10-20 fields -
    Target structure - Name -value field pair with an unbounded node on top -
                                <b>MsgAttrib 0-Unbounded
                                    Name
                                    Value</b>     
    I have to map each distinct field value from the source structure - to the Value field on target structure. The Name field in the target structure should contain the name of the source field ( it can contain a constant - field name if we cannot get the source element name during mapping runtime, thats ok )
    So basically each elementname and its value on the source structure form a record on the target xml. The next source element and its value will be mapped to the next record on the target xml - this filling up the two dimensional target structure - with as many rows as the number of source fields to be mapped. The number of such source fields to be mapped can grow . ( there should not be any limitation on that )
    Can this be accomplished using standard functions in message mapping - or should we resort to writing udfs ?
    Any right thoughts, solutions to solve this mapping scenario will be awarded points rightaway .....

    Hi karthik,
    The mapping that ur scenario requires can be accomplished using the standard functions...
    now ur source structure is unbounded...tht means it can have multiple occurences...
    and for each occurence you have a pair of values in target message under a node....
    now the important thing here is ..tht ur target node which has those two fields under it will repeat as many times as occurences of the source message...
    so u  need to map the main message type node of the source to this node in target...
    and according map the fields under tht node...
    UDF's are not required for this....
    Regards ,
    Sushil Hadge

Maybe you are looking for