如何取消另一个 class 的 ArrayList 的新值?

How to nulify and a new value to ArrayList from another class?

我想在 Processing classalchemyFuel method 之后从 Working class 中取消并将新值设置为 List flowers(删除所有元素并添加 now_flowers)完毕。我该怎么做?

Class 工作:

      import java.util.*;
      public class Working {
List <String> flower_girls = Arrays.asList("Anna", "Nina", "Alice");
List <String> garbager = Arrays.asList("Rika", "Elly");
List<Integer> flowers = new ArrayList<>();
List<Integer> garbage = new ArrayList<>();

public static void main(String[] args) {

}

public Working() {
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            flowerPicker(flower_girls);                
        }
    };
    timer.schedule(task, 0, 5000);

}

public List<Integer> getFlowerList() { return flowers; }

public int sum(List<Integer> list) {
    int sum = 0;
    for (int i : list)
        sum = sum + i;
    return sum;
}


public int flowerPicker(List<String> flower_picker) {
    int flower_picked = 1 * flower_picker.size();
    flowers.add(flower_picked);
    System.out.println("Flowers: " + sum(flowers));
    return sum(flowers);
}


}
    

Class 处理中:

        import java.util.*;

public class Processing{
List <String> alchemy_girls = Arrays.asList("Nika", "Rachel");
List <String> flower_girls = Arrays.asList("Anna", "Nina", "Alice");
List<Integer> fuel_tanks = new ArrayList<>();
Working w = new Working();
public int now_flowers;

public Processing(){
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            alchemyFuel(flower_girls);
            mechanicDetails();
        }
    };
    timer.schedule(task, 0, 15000);
}

public static void main(String[] args) {
    Processing p = new Processing();
}

public int alchemyFuel(List<String> flower_girls){
    int flower_sum = w.sum(w.getFlowerList());
    int fuel = (flower_sum/ flower_girls.size()) * alchemy_girls.size();
    fuel_tanks.add(fuel);
    now_flowers = flower_sum - fuel;
    System.out.println("Fuel: " + w.sum(fuel_tanks));
    return w.sum(fuel_tanks);
}


}

您可以初始化一个新的空 ArrayList 并将其分配给 w.flowers:

w.flowers = new ArrayList<>();