Page 2 of 2 FirstFirst 12
Results 21 to 34 of 34
  1. #21
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,414
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    Not necessary but it would work. But you could use and ArrayList or a single one-d array. I recommend the former. If you are doing this for a class you better be certain what you are and are not allowed to use.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  2. #22
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by jim829 View Post
    Not necessary but it would work. But you could use and ArrayList or a single one-d array. I recommend the former. If you are doing this for a class you better be certain what you are and are not allowed to use.

    Regards,
    Jim
    first, i dont think i getting in person help anymore. lol. person is busy. second, i am not doing this for a class, just for personal interest. But, i am trying to prep a little for a class at school. third, i'd like to use one-d array b/c it would be the easiest? but i dont exactly know how to use one-d array for this problem b/c i think i am suppose to store variables in it, but i never tried this before. (only used arrays for numbers and strings made up in the main)

  3. #23
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,414
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    You can have an array of any type, not just ints or strings. I would use a list myself because it is easier to manage. But I will give an array example. Suppose you have a class of type Foobar. You can do the following:

    Java Code:
    Foobar[] foobars = new Foobar[10];// an array which holds 10 foobar objects.
    
    // Now initialize the array:
    
    for (int j = 0; j < foobars.length; j++) {
        foobars[j] = new Foobar();
    }
    Having provided that, I have to tell you this is basic stuff which could be learned from a book. And that is what I recommend. You read the book, try coding some examples to see if you understand it. And if after several attempts you don't, this forum can be of great benefit. You can also check the tutorials in my signature (not certain if I mentioned that before). As far as checking out a book, I don't have any to recommend. That last one I used was Learning Java which was great but it has not been updated since 2005. I tend to stay away from books which try to get cute with little cartoons and that talk down to the reader.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  4. #24
    Join Date
    Jun 2013
    Posts
    70
    Rep Power
    0

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by jim829 View Post
    You can have an array of any type, not just ints or strings. I would use a list myself because it is easier to manage. But I will give an array example. Suppose you have a class of type Foobar. You can do the following:

    Java Code:
    Foobar[] foobars = new Foobar[10];// an array which holds 10 foobar objects.
    
    // Now initialize the array:
    
    for (int j = 0; j < foobars.length; j++) {
        foobars[j] = new Foobar();
    }
    Having provided that, I have to tell you this is basic stuff which could be learned from a book. And that is what I recommend. You read the book, try coding some examples to see if you understand it. And if after several attempts you don't, this forum can be of great benefit. You can also check the tutorials in my signature (not certain if I mentioned that before). As far as checking out a book, I don't have any to recommend. That last one I used was Learning Java which was great but it has not been updated since 2005. I tend to stay away from books which try to get cute with little cartoons and that talk down to the reader.

    Regards,
    Jim
    thanks you for the advice, i actually did get help in person and we did it. xD learned a lot today. I have posted quite a few forums on the site, and you seem to be helping me everytime. (thank you ^^) . is this ur job? or do u enjoy helping ppl code?

  5. #25
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,414
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    No one, not even the moderators, get paid for doing this. Everyone on this forum assists because they enjoy programming and enjoy helping others. And I also learn alot by seeing what others are doing and reading replies on topics with which I am unfamiliar.

    Regards,
    Jim
    Last edited by jim829; 07-24-2013 at 02:33 PM.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  6. #26
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,739
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by jim829 View Post
    And I also learn alot by seeing what others are doing and reading replies on topics with which I am unfamiliar.
    That's true no matter how experienced you get, you learn something new every day. But especially in the first few years of my budding career as a Java software engineer, this taught me immensely much because then you get to see what problems really occur out in the wild as apposed to the safety of the classroom or your attic, and by the time you run into them yourself you'll already be equipped to deal with them. At the very least you can parrot the answers given in repeated occurrences of the question and act like you made it up yourself :)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #27
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by gimbal2 View Post
    At the very least you can parrot the answers given in repeated occurrences of the question and act like you made it up yourself :)
    You can really get away with saying Go Google it? ;)

    I learned Java from the forums. No books, and I only ever used the Sun/Oracle tutorials like a quick reference guide to supplement the API. But for more than six months I read every word of every thread on the Sun New to Java forum. And most of the posts in CLDC/MIDP and WTK, and many in Advanced Java.

    After that I focused (no pun intended) on AWT/Swing and lost interest in a lot of other stuff like I/O and networking :)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #28
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,739
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by DarrylBurke View Post
    You can really get away with saying Go Google it? ;)
    Remember: we're talking about the golden years of forums.sun.com where the questions were still relatively original :) 'Go google it' became a trend later.

    db
    Who are you calling a dubious badger, eh?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #29
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,845
    Rep Power
    19

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by gimbal2 View Post
    Who are you calling a dubious badger, eh?
    I see the "Badger Badger Badger" tag is top again at OTN...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #30
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by gimbal2 View Post
    Remember: we're talking about the golden years of forums.sun.com where the questions were still relatively original :)
    Have you seen my sigline on the Ranch?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #31
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by Tolls View Post
    I see the "Badger Badger Badger" tag is top again at OTN...
    Whaddya mean, again? It's been at the top like forever!
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  12. #32
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,845
    Rep Power
    19

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by DarrylBurke View Post
    Whaddya mean, again? It's been at the top like forever!
    It wasn't a year or so ago (the last time I bothered looking at the tags).
    It's just rather noticeable with the current layout.

    I used to track that thing, after the move from Sun...:)

    ETA: It has changed. It only takes the current forum, and not all child forums. So it's big in New To Java, but second in Java Programming, and almost non-existent in the database connectivity forum.

    God I'm bored.
    Last edited by Tolls; 07-24-2013 at 04:19 PM.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #33
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,739
    Rep Power
    5

    Default Re: how to storing arbitrary collection of variables

    Quote Originally Posted by DarrylBurke View Post
    Have you seen my sigline on the Ranch?

    db
    Make me search for it, why don't you!

    I take it you refer to "There are no new questions, but there may be new answers." ? I like it, but it doesn't say anything about those new answers being correct or not though ;)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  14. #34
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: how to storing arbitrary collection of variables

    Lot of old answers that aren't correct floating around too :(

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Classes with arbitrary data members
    By pifrely in forum New To Java
    Replies: 3
    Last Post: 01-26-2013, 09:31 PM
  2. Combo with arbitrary content
    By BadaBingNow in forum SWT / JFace
    Replies: 0
    Last Post: 03-08-2012, 04:09 PM
  3. Arbitrary number of objects, each with a unique name.
    By providence in forum New To Java
    Replies: 8
    Last Post: 02-23-2011, 01:12 AM
  4. gradients between two arbitrary colors
    By falkon114 in forum New To Java
    Replies: 4
    Last Post: 02-09-2011, 05:08 PM
  5. Creating an arbitrary number of variables
    By theodorekon in forum New To Java
    Replies: 1
    Last Post: 04-15-2010, 06:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •