How to store objects of different types in a container?
containers, java
Solution
I'm doing this to ensure that when I save all these information to my database, i will have all these information in the same entry in the database.
Yes, you've done the correct thing by creating a class to hold all the values.
And, as you've already noted, you can then create a `List` of this objects if you wish to perform multiple database insertions/updates.
Many persistence schemes operate on the basis of defining classes (known as DAOs) to represent the data stored in individual tables. Using a persistence provider that supports annotating classes (such as Hibernate) can really simplify your interaction with a database. I'd recommend you research this topic in more detail.
Problem
I'm wondering if i can have an array ( or basically a table ) with each of its element being a set of objects of different types. I mean i want to create something like this ( i know it's incorrect in syntax, just wanna demonstrate my idea ) : ``` List<String, int, double, Date, ... , etc > list_name ``` I'm doing this to ensure that when I save all these information to my database, i will have all these information in the same entry in the database. This is because i did some web scraping from different sites to gather all these data, i.e. in the list, string may be from site A, int may be from site B, etc. I found some information may be missed for some reasons ( say, for a particular element of the list, String from site A may be missing, other data are just there, perfectly fine. ). If i store these data into seperated lists, i'm afraid there will be some mismatch of data. Now my solution is to create a class, say ClassA : ``` ClassA{ public String info1 public int info2 public double info3 .. .. public wtever info } ``` and then i will have a of list of ClassA I'm wondering if there is a better way to achieve this?