215MATLAB
®
-Specic Techniques
>> disp(hash.containsKey('2nd key'))
1 % = true
>> disp(hash.size)
2
>> disp(hash.get('key #2')) % key not found
[]
>> disp(hash.get('key #1')) % key found and value retrieved
myStr
>> values = hash.values.toArray
values =
java.lang.Object[]:
[3x3 double]
'myStr'
>> values(1)
ans =
8 1 6
3 5 7
4 9 2
>> values(2)
ans =
myStr
See §3.2.6 for a comparative implementation of a simple cache mechanism using either
containers.Map or java.util.Hashtable. There are many different kinds of Java
Collections that we can use out-of-the-box. While Hashtable may seem appropriate for
most uses, other classes may be even faster for specic uses.
648
While Java classes do not accept nonsimple MATLAB data ...