Reputation: 16375
System.out.print(">> ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
I would like to name a variable (double input=new double[5];) with the name the program gets from BufferedReader. How to do that?
Upvotes: 3
Views: 3032
Reputation: 597124
You can't do it. Variable are defined at compile-time. And you don't need it - how would you access variables with dynamic names?
You can use a Map<String, double[]>
to map a string to a double array. map.put(name, array)
and then map.get(name)
will give you the array.
Upvotes: 4
Reputation: 7613
No, you can't. It would be equivalent of changing the source code at run-time. Why do you need to do this, anyway?
Upvotes: 1