【问题标题】:How to iterate over String array?如何迭代字符串数组?
【发布时间】:2017-04-14 15:03:25
【问题描述】:

当我在 textview 中执行 setText 时,它只显示数组的前三行,我需要找到一种方法来执行 result = result + xx.split("\n");但是在不可能的字符串数组中,你能教我其他方法吗?

String xx="";
String result[] = {};

for(int i=0;i<row;i++) {
    for(int c=0;c<col;c++) {
        Cell z=s.getCell(c,i);
        //Need an alternative to this because cannot do this in string array
        result = result+ xx.split("\n");
    }
}     
textview.setText(resultado[0]+"--"+resultado[1]+"--"+resultado[2]);

【问题讨论】:

  • String xx 为空?此外,遍历result,将值添加到有问题的textView,而不是result += "something";
  • 为什么不将split 存储在一个数组中,然后通过它进行交互?
  • 字符串 xx 不为空。你能举个例子吗?
  • @nIcEcOw 你能举个例子吗?

标签: java android arrays string


【解决方案1】:

您需要更具体地说明您想要实现的目标,但这是对数组的基本迭代。

String numbers = new String[] {"1", "2", "3", "4", "5"};
String myString = "";

for (String aNumber : numbers) {
  myString += aNumber;
}

textview.setText(myString);

【讨论】:

  • 我需要将位置存储在变量中以便将它们保存在 sqlite 中
猜你喜欢
  • 2020-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-06
  • 1970-01-01
  • 2016-05-24
  • 2019-07-15
  • 1970-01-01
相关资源
最近更新 更多