简体   繁体   中英

can we insert a string into the hashtable object

Hashtable ExpiryRefData;
String icdExpiry;

try {
    ExpiryRefData = CAPSUtil.getRefData(EXPIRY);
    icdExpiry = (String) ExpiryRefData.get(EXPIRY);
}

can any body please explain how we are actually storing the string directly into the ExpiryRefData and how we are retrieving the values in the other string variable

Don't use a Hashtable . Use a Map<K, String> instead. If you need synchronized access, consider using a synchronized wrapper (refer to java.util.Collections ).

(Edit: a Map<String, String> will do. If there is special need a HashMap` is enough.

As per code stated here, CAPSUtil.getRefData(EXPIRY) returns a hashtable. Then ExpiryRefData.get(EXPIRY) returns object which is casted to String using (String) . For more detils refer CAPSUtil.getRefData(EXPIRY) implementation.

As per java Hashtable reference

public class Hashtable<K,V>
This class implements a hash table, which maps keys to values. 

Any non-null object can be used as a key or as a value.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM