我想按标题在图书馆中搜索或查找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);
}
答案 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;
}