The question is published on by Tutorial Guruji team.
I’m working on a command-based modification for Minecraft in which you are allowed to use flags (-[a-z]) to specify certain values. However, I’m slightly confused on how I should go about parsing regular arguments. Here’s an example of a command: /tp fist -h
. Of course, it’s relatively simple to what string[0] equals, but if I were to try /tp -h fist
, I’m afraid I would confuse the modification and it would throw an exception.
So, my question is: is it possible to create a String[ ] which removes a specific type of string from an existing list so I can do if(args[0].equalsIgnoreCase("text")
and it would do the same thing for /command text [text-to-remove]
as if I did /command [text-to-remove] text
?
Thanks in advance!
Sincerely,
afistofirony
PS: I know I can use a for loop to check each individual argument, but normally the variables will change for each execution (since they are usually used to specify players that don’t all share a name).
Answer
The short answer is no. You will have to either recreate a subset array of the original or keep track of the ignored indexes.
The long answer is that you could create your own collection that does this implicit filtering.
In a FP language like scala filtering a collection is much easier. Java you will have to usually loop through the collection.