what is the data structure that allows you to add different kinds of data (String, Float, int...) together? For example:
table tab = new table();
tab.add("abcdefgh");
int i=0;
tab.add(i);
float f;
tab.add(f);
...
what is the data structure that allows you to add different kinds of data (String, Float, int...) together? For example:
table tab = new table();
tab.add("abcdefgh");
int i=0;
tab.add(i);
float f;
tab.add(f);
...
You can use either collections (lists or sets) or maps. Both are generic, so in your case you should use Object
as a generic parameter:
List<Object> list = new ArrayList<>();
list.add(1);
list.add("hello");
list.add(new Date());
etc.
However it seems that you are on a wrong way. This is typically very bad practice to use untyped data. Java is a strongly typed language and java programmers tend to use this advantage.
You can also use Table from guava.
I'd recommend you to ask more specific question. I believe that you have a task and you think that storing data of different types in one place is a good idea. It is not.
I hope this helps.
If I have understand your question and you need to store in a list of related values, create an object
class MyObject{
private String sentence;
private Float score;
private String kind;
// getters and setters
}
where you can save the related values, and then add your objects to a Collection.
For example:
List<MyObject> list = new ArrayList<MyObject>();
MyObject myObject = new MyObject();
myObject.setSentence("sentence");
// initialize object fields
list.add(myObject);