Java中HashMap案例
package ch8; import java.util.*; /** * Created by Jiqing on 2016/11/27. */ public class MapTest { public static void main(String[] args) { // Map不同于List,它的key不一定是数字 Map map = new HashMap(); map.put("疯狂Java讲义",109); map.put("疯狂iOS讲义",10); map.put("疯狂Ajax讲义",79); // 如果新的value覆盖了原有的value,该方法返回被覆盖的value System.out.println(map.put("疯狂iOS讲义",99)); // 输出10 System.out.println(map); // 判断是否包含指定key System.out.println("是否包含值为疯狂iOS讲义key:"+map.containsKey("疯狂iOS讲义")); System.out.println("是否包含值为99 value:"+map.containsValue(99)); // 遍历map for (Object key : map.keySet()) { System.out.println(key+"-->"+map.get(key)); } } }
输出结果:
10 {疯狂Ajax讲义=79, 疯狂iOS讲义=99, 疯狂Java讲义=109} 是否包含值为疯狂iOS讲义key:true 是否包含值为99 value:true 疯狂Ajax讲义-->79 疯狂iOS讲义-->99 疯狂Java讲义-->109
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6107637.html,如需转载请自行联系原作者

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
android Handler消息处理源码剖析
1、什么是Handler A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it --from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue. Handler允许你发送和处理Message(消息)/Runnable对象到当前...
- 下一篇
RxAndroid、RxJava的fromCallable更新数据加载到ListView简例
RxAndroid、RxJava的fromCallable更新数据加载到ListView简例 Java代码: package zhangphil.app; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import andr...
相关文章
文章评论
共有0条评论来说两句吧...