迭代地图并调用另一种方法

编程入门 行业动态 更新时间:2024-10-23 19:23:43
本文介绍了迭代地图并调用另一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Map< Integer,Integer> result1 = jmxService.generateMabc(p1,p2,p3,p4);

现在地图结果1将包含oif键值对作为usal 现在我想逐个迭代地图,获取地图的值,该值为key和value,它将为integer类型,并将其转换为字符串并存储字符串两个字符串变量,如下所示

string j =将存储键 string t =将存储值

amd然后传递这两个参数到另一个方法调用,它将通过字符串j和string t作为参数,一旦它们通过我想要j和t为null,以便在下一次迭代中,相同的过程可以继续,直到时间映射具有值c你可以告诉我如何实现这一点,我试过的是...。(b)

for(Map.Entry< Integer,Integer>条目:result1.entrySet()) { String j,t; j = entry.getKey(); t = entry.getValue(); abc .callanothermethod(string p1,stringp2,stringj,string t) j = null; t = null; }

请告知什么是正确的appoach获得相同的。 >

解决方案

整数不是字符串。所以 j = entry.getKey()没有意义。

您需要将Integer转换为String(例如通过调用 toString()):

j = entry.getKey()。toString();

您真的需要学习

  • 从编译器中读取错误消息,告诉您waht是错误的,并且
  • 读取您正在使用的类的javadoc,了解您可以

I am getting an map as shown below inside a method

Map<Integer, Integer> result1 =jmxService.generateMabc(p1, p2,p3,p4);

now the map result 1 will consists oif key value pair as usal now i want to iterate over the map one by one , fetch the value of the map that is both key and value which will be of type integer and convert them into string and store the string two string variables like shown below

string j = will store the key string t = will store the value

amd then pass these two parameters to another method call which wil take string j and string t as parameter once they pass i want j and t to be null so that in next iteration the same process and can be continued till the time map has value c an you please advise how to achieve this, what I have tried is..

for (Map.Entry<Integer, Integer> entry : result1.entrySet()) { String j, t; j=entry.getKey(); t= entry.getValue(); abc .callanothermethod(string p1,stringp2, stringj, string t) j=null; t=null; }

please advise what will be the correct appoach to obtain the same.

解决方案

An Integer is not a String. So j = entry.getKey() doesn't make sense.

You need to transform the Integer into a String (by calling toString() for example):

j = entry.getKey().toString();

You really need to learn to

  • read the error messages from the compiler, which tell you waht is wrong and where
  • read the javadoc of the classes you're using, to understand what you can do with them.

更多推荐

迭代地图并调用另一种方法

本文发布于:2023-11-27 03:06:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636308.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:种方法   迭代   地图

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!