Results 1 to 6 of 6

Thread: Creating a vector type of a class

  1. #1
    Join Date
    Jul 2009
    Posts
    127

    Creating a vector type of a class

    Hello,
    Here is my problem, I have to do a project on a game board.
    Here is the part of my code
    Code:
     Public class game{
            private cs [] boxes;     / / The board game
            ...
    }
     
    Public class cs{
           private int nbGraines;      / / Number of seeds in this box
           ...
    }
    I understood when declaring an array type was due int, double, string, ... but the class I can not follow. And even if it was the type of class, I see how the implementation. Basically, I want to create a vector type of class.

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: Creating a vector type of a class

    Hello,
    Your Table boxes you can store objects of type Box is everything. As an array of type int you permanent store integers. It's just a way to store objects (in this case for you of Case). After you if your picture trail you will retrieve objects Case and you can work on it (using the methods that will be in your class Case). Hope you are understanding the things very well.

  3. #3
    Join Date
    Nov 2009
    Posts
    446

    Re: Creating a vector type of a class

    Hello,
    What you should know is that a vector is an array of Object i So you can meter all what you want provided it is an Object (except always double boolean char int ...) and what inherited. After seeing when you retrieve your object you must know what it is if you want to use these methods. Therefore you cast your object in Case.
    Example:
    Code:
    Case c = (Case)mvec.elementAt(35);

  4. #4
    Join Date
    Nov 2009
    Posts
    359

    Re: Creating a vector type of a class

    Hello,
    An important note:

    - A table is an object of Java static length, that is to say that the number of items may contain fixed.

    - A vector is a dynamic array (such linked list or other) ie its length set initially at 10 is variable and not static.

    This implies it is advisable to use Vector rather than tables. Indeed in a table you are obliged to establish an optimal length and therefore reserve memory space result with a Vector this benefit is minimal and adjusts to any time. Moreover the use of tables is not recommended because it does not fit into the philosophy of the approach object (any object) in Java. Eventually it is rather advisable to use the class ArrayList (not synchronized, in case you do not have concurrency course ...) and thus less CPU time consuming. For more information see the API reference collections at sun.

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    Re: Creating a vector type of a class

    Hello,
    If in an application, the number of object you have is fixed, it is preferable that you use a table. Why, because the Vector class, as the ArrayList class, simply use a table, they increase in size as and when. By cons, for the variables set in the original vectors as in the Array, there is a manufacturer who can change the default value of 10, and its increment. And yes the Vector object is simply to initialize an array object of size 10 therefore also fixed ;-). And it will increment according to the needs of 10 by default. But here it will go through System.arraycopy. If you need any more help on this, then please do post back.

  6. #6
    Join Date
    Nov 2009
    Posts
    583

    Re: Creating a vector type of a class

    Hello,
    Well you're right of course. The vector mask the underlying implementation in tabular form, but at least they provide methods to add, delete, or browse. They provide a class Iterator o how valuable that hides the implementation of the trail of a table, Of course you'll tell me, you can create a class Iterator on a table. In other words I recommend the Vector and consortium for readability and simplicity of understanding.

Similar Threads

  1. Creating a generic class in dot net
    By Vedic in forum Software Development
    Replies: 4
    Last Post: 16-02-2011, 08:51 AM
  2. Vector class and exceptions
    By Logan 2 in forum Software Development
    Replies: 5
    Last Post: 24-02-2010, 03:57 AM
  3. Function problem with Vector Class
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 12:52 AM
  4. How to sort vector objects by class member variables in c++?
    By Linoo in forum Software Development
    Replies: 4
    Last Post: 29-01-2010, 07:15 PM
  5. Creating a Vector Object in Java
    By Coldman in forum Software Development
    Replies: 4
    Last Post: 04-03-2009, 02:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,138,393.34462 seconds with 17 queries