Results 1 to 2 of 2
Thread: Array of different data types?
- 08-27-2008, 05:33 PM #1Member
- Join Date
- Aug 2008
- Rep Power
Array of different data types?
I want to store some data in an array as below
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......
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.
- By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:36 PM
- By Java Tip in forum Java TipReplies: 0Last Post: 03-28-2008, 08:29 PM
- By bluekswing in forum New To JavaReplies: 4Last Post: 01-12-2008, 01:48 AM
- By adlb1300 in forum New To JavaReplies: 8Last Post: 11-05-2007, 03:01 AM