我有一個類如何從ArrayList <String[]>獲取String [],我想實際從ArrayList <String[]>獲得索引0處的String?
public class DataRatesString {
private String[] ab1 = {"Auto moto sdhv davjdn adadk", "Rs. 355"} ;
private String[] ab2 = {"sjg atoiu ", "Rs. 200"} ;
private String[] ab3 = {"go to UTOP atup auto", "Rs. 3279"} ;
private String[] ab4 = {"Hid to putho", "Rs. 2424"} ;
private String[] abo5 = {"pithoo to bittu", "Rs. 8457"} ;
private ArrayList<String[]> abCollection = new ArrayList<>();
public void setAbCollection() {
abCollection.add(ab1);
abCollection.add(ab2);
abCollection.add(ab3);
abCollection.add(ab4);
abCollection.add(ab5);
}
public ArrayList<String[]> getAbCollection(){
return abCollection;
}
}
我還有一個類從我打電話列表
DataRatesString dataRatesString = new DataRatesString();
dataRatesString.setAbCollection();
ArrayList<String[]> ratesarray = dataRatesString.getAbCollection();
現在我想在ArrayList中的String []
的0位置的所有字符串我在同一個類中創建了一個方法,但是因爲我是java新手,我無法弄清楚如何執行它。
這是我試圖讓
private List<String> getRatesItemNamelist(){
String[] arraylist;
ArrayList<String> list = new ArrayList<>();
arraylist = new String[ratesarray.size()];
for (int i = 0; i < ratesarray.size(); i++) {
arraylist = ratesarray.get(i);
}
list.add(0, arraylist[arraylist.length]);
return list;
}
這不是工作方法。