For example I have a class 'myClass' and I create an array
or a method declaration as
then what is the signifigance of this?
I am currently trying to understand how ArrayList work. Here is a bit of code I wrote with help from a book. The questions are mentioned in the comments within the code.
import java.util.*;
import java.io.*;
class dvdInfo
{
String title;
String leadActor;
String genre; //can I declare them as dvdInfo title? What actually happens if I do that?
dvdInfo(String t, String l, String g)
{
title = t;
leadActor = l;
genre = g;
}
public String toString()
{
return title + " " + leadActor + " " + genre;
}
}
class Main
{
public static void main(String[] args)
{
ArrayList<dvdInfo> dvdlist = new ArrayList<>();
String t,l,s;
Console c = System.console();
int i;
for(i=0; i<5; i++)
{
t = c.readLine("Enter the title\n");
l = c.readLine("Enter the lead Actor\n");
s = c.readLine("Enter the genre\n");
dvdInfo d = new dvdInfo(t, l, s);
dvdlist.add(d); // Doesn't this imply dvdlist.add(d.toString()) ? Now, what type of object is actually getting added to the ArrayList? An object of type String or dvdInfo? I know the answer is logically dvdInfo but I
//am kinda confused.
}
System.out.println(dvdlist);
}
}
Thank you for all those who help me out. Any kind of help is really appreciated.