1. Download our Official Android App: Forums for Android!

Apps create a static array of objects in java?

Discussion in 'Android Development' started by aidanmack, Jan 1, 2014.

  1. aidanmack

    aidanmack Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Jan 1, 2014

    Jan 1, 2014
    3
    0
    5
    Hi,
    Im a little new too java programming. Im looking for a means to store groups of static data..
    so I understand these simple string arrays...

    [HIGH]
    private static String[] names = new String[] {
    "aidanmack",
    "johnsmith"
    }
    private static String[] ages = new String[] {
    "30",
    "30"
    }
    [/HIGH]


    But can I not combine that into an array of objects? somthing along the lines of what you would do with json? like...

    [HIGH]
    private static array[] multi = new array(){
    {"name":"AIDANMACK","age":"30"},
    {"name":"johnsmith","age":"31"}

    }
    [/HIGH]

    Thanks
    Aidan
     

    Advertisement

  2. venom2124

    venom2124 Newbie
    Rank:
    None
    Points:
    36
    Posts:
    23
    Joined:
    Jan 6, 2014

    Jan 6, 2014
    23
    1
    36
    Male
    Developer
    North Carolina
    The problem I see is you have two different types of variables. String and Int's and if I'm not mistaken you can't do that with an array. This is were classes and objects come into play with different attributes and methods.
     

Share This Page

Loading...