的Java添加在列表的末尾 [英] Java adding at the end of the list

查看:146
本文介绍了的Java添加在列表的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一本书类。我要在名单

i have a book class . I want to add a element at the end of the list

public class Book {
private String title;
private String authorName;
private double price;


/**
 * @param title
 * @param authorName
 * @param price
 */
public Book(String title, String authorName, double price) {
    setTitle(title);
    setAuthorName(authorName);
    setPrice(price);
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getAuthorName() {
    return authorName;
}

public void setAuthorName(String authorName) {
    this.authorName = authorName;
}

public double getPrice() {
    return price;
}

public void setPrice(double price) {
    this.price = Math.abs(price);
}

}

和它有一个方法追加到图书添加到列表中,但我无法弄清楚如何进入一个值列表的书目类

and a Booklist class which has a method append to add the books into the list but i am not able to figure it out how to enter a value into a list

public class BookList {

/**
 * books will be stored in an array of strings
 */

private Book[] books;
// *** TODO *** you will need to add more private members variables

public BookList(int N) {
    // TODO Auto-generated method stub  
}



public void append(Book book) throws BookListFull {
    // TODO Auto-generated method stub 
}

}

我想在列表的末尾添加元素好心帮我该怎么办呢
谢谢

i want to add element at the end of the list kindly help me how to do it thanks

推荐答案

1 我会鼓励你使用集合框架的Java,而不是阵列。

1. I will encourage you to use Collection framework of Java instead of Arrays.

2 收藏会给你很多的灵活性和方法,使你可以处理你在更前pressive方式的数据。

列表<图书>名单=新的ArrayList<图书取代;

例如:

     List<Book> list = new ArrayList<Book>;

     list.add(new Books(title, authorName, price));

这篇关于的Java添加在列表的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆