Java question

Discussion in 'Forum Software Development' started by Osphisa, Mar 5, 2019.

  1. Osphisa

    Osphisa Neophyte

    2
    1
    +0
    I'm not a java person so this may have a simple answer, but I just don't know it.

    I have an object that has multiple elements of the same naming format i.e. element0, element1, element2, etc

    Right now, I am adding them to a an ArrayList in the following manner:

    Code:
    list.add(element0);
    list.add(element1);
    ...
    So on and so forth.

    They are all of the same type but there are other elements that are also of the same type but not of the same naming convention (plus, I won't really be using them in the same manner). Is there any way to add these elements to the list in a looping manner? Something like:

    Code:
    for(int X=0; i<SIZE; X++)
    list.add(elementX);
    I know how to get cute and do this type of thing in C-based languages but not in java. As it is, it looks really hacky and messy and I'd like to clean it up if at all possible.
     
  2. Boothby

    Boothby Enthusiast

    132
    43
    +100
  3. Osphisa

    Osphisa Neophyte

    2
    1
    +0
Verification:
Draft saved Draft deleted
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.