Advertisement
SensaBG

case "Steal":

Feb 17th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.62 KB | None | 0 0
  1.  int removeLastItems = Integer.parseInt(command.split(" ")[1]);
  2.                     List<String> removedItems = new ArrayList<>();
  3.  
  4.                     if (removeLastItems > chest.size()) {
  5.                         removeLastItems = chest.size();
  6.                     }
  7.                     for (int i = 0; i < removeLastItems; i++) {
  8.                         removedItems.add(chest.get(chest.size() - 1 - i));
  9.                     }
  10.                     chest.removeAll(removedItems);
  11.                     Collections.reverse(removedItems);
  12.                     System.out.println(removedItems.toString().replaceAll("[\\[\\]]", ""));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement