Results 1 to 2 of 2
  1. #1
    venkatteshb is offline Member
    Join Date
    Aug 2008
    Rep Power

    Default Array of different data types?

    Hello Everybody,

    I want to store some data in an array as below

    arr[0][0]="12,1", 5
    arr[0][1]="12,2", 7

    like above....

    where "12,1", " 12,2" are strings, and 5,7 are integers.....

    is it possible, i.e. is there any feature available in java by default to do that?

    Else, i will have to convert 5,7 to strings and store and once when i want them as integers, i will have to convert again.

    pl give me any suggestions......

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    Best answer: don't do this. Sure you could try to use an array of Object and store String and Integer objects, but you'll end up with an ungodly mess that will be hard to debug and impossible to maintain.

    Much better is to create a class that holds a String and an int and then have a one dimensional array that holds objects of this class (or perhaps better still, have an ArrayList that holds these objects).
    Last edited by Fubarable; 08-27-2008 at 05:48 PM.

Similar Threads

  1. Replies: 0
    Last Post: 04-17-2008, 07:36 PM
  2. Primitive data types of Java
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-28-2008, 08:29 PM
  3. Converting data types
    By bluekswing in forum New To Java
    Replies: 4
    Last Post: 01-12-2008, 01:48 AM
  4. Add data to an array
    By adlb1300 in forum New To Java
    Replies: 8
    Last Post: 11-05-2007, 03:01 AM

Posting Permissions

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