Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java list items

Tags:

java

list

Im using the following code

List<String> text = new ArrayList<String>();
text.add("Hello");

So that list will only accept Strings to be added, how can I add into one list more types of variables like ints and strings together like

Adding into the text list some rectangle values like

rectangle name, rectangle width, rectangle height

So later I can access them in a loop

like image 706
Raggaer Avatar asked Apr 17 '14 15:04

Raggaer


1 Answers

Create your own Rectangle class and store those values in it.

List<Rectangle> rectangles = new ArrayList<>();
rectangles.add(new Rectangle("Foo", 20, 30));
like image 118
Duncan Jones Avatar answered Nov 14 '22 12:11

Duncan Jones