Results 1 to 2 of 2
Thread: Array of different data types?
- 08-27-2008, 05:33 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 16
- Rep Power
- 0
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......
-
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
-
Use Scanner to read various types of data from a file
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:36 PM -
Primitive data types of Java
By Java Tip in forum Java TipReplies: 0Last Post: 03-28-2008, 07:29 PM -
Converting data types
By bluekswing in forum New To JavaReplies: 4Last Post: 01-12-2008, 12:48 AM -
Add data to an array
By adlb1300 in forum New To JavaReplies: 8Last Post: 11-05-2007, 02:01 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks