gpt4 book ai didi

java - 将 ArrayList 值动态传递给其他 ArrayList

转载 作者:行者123 更新时间:2023-12-01 04:51:34 25 4
gpt4 key购买 nike

我有四个长度相同的数组(例如 array1、array2...array4),我想将这些数组的值动态传递到示例数组,以便我可以添加条件和得到相应的值。我该怎么做?

   public SectionListItem[] exampleArray = { // Comment to prevent re-format
new SectionListItem("array1 data","array2 data","array3 data", "array4 data")

};

private StandardArrayAdapter arrayAdapter;
private SectionListAdapter sectionAdapter;
private SectionListView listView;


@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
arrayAdapter = new StandardArrayAdapter(this, R.id.example_text_view, exampleArray);
sectionAdapter = new SectionListAdapter(getLayoutInflater(), arrayAdapter);

listView = (SectionListView) findViewById(android.R.id.list);



setListAdapter(sectionAdapter);
listView.setAdapter(sectionAdapter);



}

最佳答案

这是一个简单的例子:

public class array3 {
public static void main(String[] args) {
int ar3[]={33,45,67,87,34,56};
int ar4[]={5,8,9,22,3,4};
List list1=new ArrayList();
List list2=new ArrayList();
for (int i = 0; i < ar3.length; i++) {
list1.add(ar3[i]);
}
for (int i = 0; i < ar4.length; i++) {
list2.add(ar4[i]);
}
list1.addAll(list2);
System.out.println(list);
}
}

关于java - 将 ArrayList 值动态传递给其他 ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14873513/

25 4 0