• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass a constructor using arraylist

 
Ja King
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.util.*;
class ArrayLists
{
public static void main(String args[])
{
ArrayList<DvdInfo> dvdList = new ArrayList<DvdInfo>();
//i want to pass the string value("Caddy Shack/comedy/Murray, Bill")
//dvdList("Caddy Shack/comedy/Murray, Bill");
System.out.println(dvdList);
}
}
class DvdInfo
{
String title,genre,actors;
DvdInfo(String title,String genre,String actors)
{
this.title = title;
this.genre = genre;
this.actors = actors;
}
public String toString()
{
return title+ " " +genre+ " " +actors;
}
}


 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think want you want is..



Also, please put your code between the code tags ...
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add a DvdInfo object to an array list, you create the object, and call "add()" on the list:



or on one line:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic