switch (args[0]) { case "-u": { int id = Integer.parseInt(args[1]); String name = ""; for (int i = 2; i < args.length - 2; i++) { name += args[i] + " "; } if (name.length() > 30) name = name.substring(0, 30); String price = args[args.length - 2]; if (price.length() > 8) price = price.substring(0, 8); String quantity = args[args.length - 1]; if (quantity.length() > 4) quantity = quantity.substring(0, 4); Product productUpdate = null; for (Product p : productList) { if (p.id == id) { productUpdate = p; } } if (productUpdate != null) { productUpdate.name = name; productUpdate.price = price; productUpdate.quantity = quantity; } break; } case "-d": { int id = Integer.parseInt(args[1]); Product delProduct = null; for (Product p : productList) { if (p.id == id) delProduct = p; } if (delProduct != null) { productList.remove(delProduct); } break; } }