11.6(使用ArrayList)编写程序,创建一个ArrayList,然后向这个列表中添加一个Loan对象、一个Date对象、一个字符串和一个Circle对象,然后使用循环调用对象的toString()方法来显示列表中所有的元素。 11.6(Using ArrayList)Write a program, create an ArrayList, add a loan object, a date object, a string and a circle object to the list, and then use the tostring() method of the object to display all the elements in the list.
参考代码:
package chapter11;
import chapter10.Loan;
import javafx.scene.shape.Circle;
import java.util.ArrayList;
import java.util.Date;
public class Code_06 {
public staticvoidmain(String[] args){
ArrayList<Object> list = new ArrayList<>();
list.add(new Loan(2.5,1,100));
list.add(new Date(100));
list.add(new String("java"));
list.add(new Circle(2));for(int i =0;i < list.size();i++)
System.out.println(list.get(i).toString());}}
结果显示:
chapter10.Loan@470e2030
Thu Jan 0108:00:00 CST 1970
java
Circle[centerX=0.0, centerY=0.0, radius=2.0, fill=0x000000ff]
Process finished with exit code 0
第十一章第六题(使用ArrayList)(Using ArrayList)11.6(使用ArrayList)编写程序,创建一个ArrayList,然后向这个列表中添加一个Loan对象、一个Date对象、一个字符串和一个Circle对象,然后使用循环调用对象的toString()方法来显示列表中所有的元素。11.6(Using ArrayList)Write a program, create an ArrayList, add a loan object, a date object, a strin