I'm still having issues creating an array to store the infos of my CSV file . Here is an example of my csv - file.
Time;Data0;Data1;Data2;
27.08.2013 00:00:00;nan;nan;nan;
27.08.2013 00:10:00;0;1;2;
As you can see, they are 3 types. -String : name of the column (eg Time
), or nan
-NotANumber-. -Double : for the values of Data0
, Data1
, Data2
. -Timestamp : for the Time
value.
The name of the columns are always on the first line of the file. I can have a very huge number of rows and columns.
So now my question: what is the easiest way of getting those information, and storing them in an Array - like form ? I need to access the informations easily, by example by searching the field named Data0
i want to be able to access to nan
and to 0
.
What i did : I tried to store this into a map, but it was not what I wanted (or obviously I didn't used it right). Furthermore I was limited to two elements, I have three. I also tried to do this in an array, but because an array can be defined only after one type in Java, I tried to make it after a class:
public class StorageArray {
String nameColumn;
Double contentLine;
Timestamp time;
}
But then I couldn't figure out how to store the different types in the different variables in my class.
I'm a Java beginner, so maybe there is an easy way to do what I want? If you want me to provide more code, I can, but I wanted to keep the question as simple as possible.
A friend told me to use introspection and object-relational mapping (ORM). But it seems quite difficult for me.
I don't think you need Double contentLine
.
Use LinkedHashMap<String /*nameColumn*/,Timestamp /*time*/ >
.
Stored index in your map its your row.
Other way, use Linkedlist<SomeYourClass>
where SomeYourClass
is represented your row (I think it will be easy to handle):
public class Row
{
List<String> nameColumnList;
//Double contentLine; /* you don't need it*/
Timestamp time;
// ...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.