迭代一组 [英] Iterate through a set

查看:64
本文介绍了迭代一组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下集合包含整数,我需要用十替换10的倍数。任何人都可以指导我正确的方向吗?如何用整数替换字符串。





The following set contains integer, I need to replace any number which is multiple of 10 by "ten". Can anyone guide me in the right direction please?? How can I replace strings by integers.


descendingOrder=(TreeSet<Integer>)sortedSet.descendingSet();
       System.out.println("The sorted list is:");
       System.out.println(descendingOrder);

推荐答案

您不能直接用不同的类型替换类型。但是(如果我正确理解你的问题),在打印列表时,你只需要检查每个值以查看它是否是10的倍数,如果是,则打印一些字符串信息而不是值。
You cannot directly replace a type by a different type. However (if I understand your question correctly), while printing the list, you just need to check each value to see if it is a multiple of 10, and if so print some string information instead of the value.


这篇关于迭代一组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆