I would like to initialize an array whose type is specified by the user through the command line. That is, if the user enters "int", I would like:
ArrayList<Integer> res = new ArrayList<Integer>();
Similarly, if the user enters "String", I would like:
ArrayList<String> res = new ArrayList<String>();
Now, of course, I can do this, a bunch of if-else instructions, but I wonder if there is a smart way to do this. Assume that user-entered types are always primitive types, i.e. Int, string, boolean, etc.
source
share