当前位置:编程学习 > JAVA >>

这个参数是数组是方法是什么意思

private static Properties getValue(String[] variants) throws NoKeyException
{
Properties properties = new Properties();
for (String variant : variants) {
String key = variant;
String value = monitorClient.getValue(key);
if(value == null)
throw new NoKeyException(variant);
     properties.put(variant, value);
}
return properties;
}

读不懂这个方法里的每一行意思,求解! --------------------编程问答-------------------- LZ的标题我没有看明白。。请重新整理一下? --------------------编程问答-------------------- 感觉像是在写properties 文件。“monitorClient”这个类在哪定义的?  --------------------编程问答-------------------- 传入一组key
然后获取这些key在monitorClient里是否存在
不存在就抛出NoKey异常 存在就put进properties里 --------------------编程问答-------------------- --------------------编程问答-------------------- 供楼主参考!

private static Properties getValue(String[] variants) throws NoKeyException
{
Properties properties = new Properties();//创建properties对象,Properties类是HashMap的子类,其最大的特点是Key和Value都是String
for (String variant : variants) {//通过遍历传进来的variants数组中的每一个元素
String key = variant;//设置key
String value = monitorClient.getValue(key);//取出monitorClient中与key对应的value
if(value == null)//判断value是否为空,若不为空,将对应的key和value添加至properties对象中。若为空,抛出NoKeyException异常
throw new NoKeyException(variant);
properties.put(variant, value);
}
return properties;
}
--------------------编程问答-------------------- 参数为记录KEY的数组,使用monitorClient能找到每个KEY对应的值,最后再把key和值存到properties里。就是用参数封装出一个properties然后作为返回值,properties用来做什么就不知道了。 --------------------编程问答-------------------- 供楼主参考!
private static Properties getValue(String[] variants) throws NoKeyException
{
Properties properties = new Properties();// 创建properties对象,Properties类是HashMap的子类,其最大的特点是Key和Value都是String
for (String variant : variants)
{// 通过遍历传进来的variants数组中的每一个元素
String key = variant;// 设置key
String value = monitorClient.getValue(key);// 取出monitorClient中与key对应的value
if (value == null) // 判断value是否为空,若不为空,将对应的key和value添加至properties对象中。若为空,抛出NoKeyException异常
throw new NoKeyException(variant);
properties.put(variant, value);
}
return properties;
}
--------------------编程问答-------------------- 为什么我的回复经常被吃掉呢, --------------------编程问答-------------------- 5楼我就回复过了,为什么没有了呢? --------------------编程问答--------------------
引用 9 楼 xiongyu2006 的回复:
5楼我就回复过了,为什么没有了呢?

版主删了? --------------------编程问答-------------------- 通过key找出一个数组variants里面是否有key对应的value,没有就抛出一个异常 --------------------编程问答--------------------
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,