在图书馆中按书名查找书(出现空错误)

时间:2018-11-11 11:59:40

标签: java

我想按标题在图书馆中搜索或查找Book,我也为Utils类编写了方法

private long[] findBookItems(String title) {
    ArrayList<Long> itemList = new ArrayList<>();
    for (BookItem book : this.bookItems) {
        if (book.getBook().getTitle().equals(title)) {
            itemList.add(book.getId());
        }
    }
    return Utils.toArrayList(itemList);
}

1 个答案:

答案 0 :(得分:0)

here is Utils class methods

public static Item[] findMethod(Item[]... arrays) {
    int n = 0;
    for (Item[] array : arrays) {
        n += array.length;
    }
    Item[] lastArray = new Item[n];
    int i = 0;
    for (Item[] array : arrays) {
        for (Item element : array) {
            lastArray[i] = element;
            i++;
        }
    }
    return lastArray;
}

public static long[] toArrayList(ArrayList<Long> list) {
    long[] ItemId = new long[list.size()];
    int n = 0;
    for (Long item : list) {
        ItemId[n] = item;
        n++;
    }
    return ItemId;
}