String sharerUserId = "", subCommand = "", repository = "";
if (jsonNode != null) {
String[] commands = jsonNode.asText().split(" ");
sharerUserId = commands[0];
StringBuilder subCommandBuffer = new StringBuilder();
for (int i = 1; i < commands.length - 1; i++) {
subCommandBuffer.append(commands[i]);
subCommandBuffer.append(" ");
}
subCommand = subCommandBuffer.substring(0, subCommandBuffer.length() - 1);
repository = commands[commands.length - 1];
}
}
In the above code i am extracting sharerUserId subCommand and repository from jsonNode.Map map = new HashMap() ;
setMap(map) ;
String command = map.get("subcommand") ; // Fails - can you see why?
public void setMap(Map map) {
map.put("subCommand", command) ;
}
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.
TRUSTED BY
ASKER
I thought of one more approach... What if i take the code out into a separate function and pass a map like :
Map map = new HashMap<>();
into the function... and then set the three values sharerUserId, subCommand, and repository inside the map... This will also work...
What do you think of this approach compared to the above one which you suggested...
Is there any pros or cons in this ??
Thanks