public class Cat {
public static ArrayList<> cats = new ArrayList<>();
public Cat() {
}
public static void main(String[] args) {
for(int x = 0; x>10; x++) {
Cat cat1 = new Cat;
cats.add(cat1);
}
printCats();
}
public static void printCats() {
System.out.println(cat1);
}
}
My Array Does not work, any hints?
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Michael
22 January 2020, 20:41
Add: w3schools, there you find all you need to solve your task.
. If you have further queries, go to +1
Anthony Chalk
16 January 2020, 11:11
When you declare an ArrayList you have to specify what type of Objects the list will contain i.e.
In this case, the ArrayList will take Cat objects 0
Amo programmareExpert
30 August 2022, 16:56
Hey Anthony, this is the part I found a little confusion, especially when doing research on ArrayLists.
What do they mean exactly by object type here: ArrayList<object type> list = new ArrayList<>(); All the examples I could find online where the types of String, integer, etc. Also why is it not listed in the second <>.
0