I want to know how i can achieve the below statement
String x = "abc";
Now i want to create an int variable which is same value as x i.e. String x="$abc"; int $abc = 5.
Please help me.
If you'd like your integer to hold the equivalent value to your String, use [url=http://java.sun.com/javase/6/docs/api/java/lang/Integer.html#parseInt(java.lang.String)]Integer.parseInt(x)[/url].
If you want to assign the value [i]5[/i] to a variable you address by name, you can use reflection: [url=http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getField(java.lang.String)]getClass().getField(x)[/url].[url=http://java.sun.com/javase/6/docs/api/java/lang/reflect/Field.html#setInt(java.lang.Object, int)]setInt(this, 5)[/url].
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.