HashMap 用物件當 Key === ```java= public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Object objectOne = new Object(); Object objectTwo = new Object(); Object objectThree = new Object(); // Key 是 Object 型態,Value 是 String 型態。 HashMap<Object, String> mapOne = new HashMap<>(); mapOne.put(objectOne, "ValueOne"); mapOne.put(objectTwo, "ValueTwo"); mapOne.put(objectThree, "ValueThree"); String result = mapOne.get(objectOne) + "\n" + mapOne.get(objectTwo) + "\n" + mapOne.get(objectThree) + "\n"; TextView v = new TextView(this); v.setText(result); setContentView(v); } } ``` ## Ref. [https://chris930921.gitbooks.io/android-traveling-gitbook/content/listview/hashmap.html](https://chris930921.gitbooks.io/android-traveling-gitbook/content/listview/hashmap.html) ###### tags: `實作相關`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up