public boolean addSubClass(Week week, int startTime, int endTime, boolean[] weekNumber) {
boolean result = false;
boolean repeat = false;
if (repeat != true) {
SubClass s = new SubClass(week);
s.updateTime(startTime, endTime);
s.updateTime(weekNumber);
subClassList.addLast(s);
result = true;
}
return result;
}
situation: this is part of my code. I got 3 differnet startTime, endTime and weekNumber in my file, when I check for first startTime and endTime, these integers are added into the list successfully, but when I check for the weekNumber, it always get the Last one that on the list.
question: can I add boolean array into the linked list???
In Java a
LinkedList(or any other generic collection, for that matter) can only contain elements of the same type. In your question it seems (you should post the code) that you have a list of Integers, and that’s the only type of objects you can add to the list: Integers. WithaddLastyou can’t add an array of booleans; not even an array of Integers, only a singleInteger.What you could do for adding several items of the same type at the end of the list, is using
addAll, like this: