1.我假设您要存储多个标题。
我正在使用ArrayList<String>
比. Array
创建一个 ArrayList 并存储所有标题值:
ArrayList<String> titleArr = new ArrayList<String>();
for (int i = 0; i < jArray3.length(); i++) {
news_id = Integer.parseInt((json_data.getString("news_id")));
news_title = json_data.getString("news_title");
titleArr.add(news_title);
}
2.现在将其发送到 another class
,您需要在单行中显示所有标题。
new AnotherClass().alistToString(titleArr);
// This line should be after the for-loop
// alistToString() is a method in another class
3.另一种类结构。
public class AnotherClass{
//.................. Your code...........
StringBuilder sb = new StringBuilder();
String titleStr = new String();
public void alistToString(ArrayList<String> arr){
for (String s : arr){
sb.append(s+"\n"); // Appending each value to StrinBuilder with a space.
}
titleStr = sb.toString(); // Now here you have the TITLE STRING....ENJOY !!
}
//.................. Your code.............
}