【问题标题】:how to store an Iterator value in a String in android如何将迭代器值存储在android中的字符串中
【发布时间】:2011-05-18 11:42:52
【问题描述】:

在我的应用程序中,当我单击一个按钮时,它会点击一个 URL 并返回一个 xml 文件。从那个 xml 文件中,我使用 dom 解析器和迭代器列出了一个特定的标签。使用以下代码,我列出了 logcat 中的数据。

Iterator<String> itr = arl.listIterator();
            int z=0,x=0,increment=0;
            while (itr.hasNext()) 
            {
                Log.e("ViewImage5-list all  "+z, itr.next());
                z++;
            }

现在我在 logcat 中获得的所有值我想将这些值存储在一个数组字符串中。如何存储它。请用代码解释.....

【问题讨论】:

  • 您能否再解释一下(最好用代码),您的解析器和迭代器是如何工作的?
  • 当您迭代时,只需将所有迭代值存储在临时字符串变量中。当你的循环完成时,你可以在你的字符串常量中存储临时字符串变量..
  • 如果迭代器具有多个值,则必须将其存储在字符串数组中。

标签: java android iterator


【解决方案1】:

试试这个:

Iterator<String> itr = arl.listIterator();
            int z=0,x=0,increment=0;
            List<String> strings = new ArrayList<String>();
            while (itr.hasNext()) 
            {
                String data = itr.next();
                list.add(data);
                Log.e("ViewImage5-list all  "+z, data);
                z++;
            }
            // the list "strings" now holds all your strings

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    • 2015-07-16
    • 2014-11-20
    • 1970-01-01
    • 2019-07-15
    • 2016-08-06
    • 2011-09-03
    相关资源
    最近更新 更多