Can Java use a String as an index array key?
Example:
array["ab"] = "ab";
No you cannot. Array
index must be integer
.
And if you want to pair them up, look at Map
, where you can use String as a key and value Map<String,String>.
Map<String,String> map = new HashMap<String,String>();
map.put("ab","ab"); //adding key-value;
String value map.get("ab"); //gives you "ab"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.