[英]Error in placing values in an object class inside an ArrayList
我正在嘗試創建一個表(2d),其中每個單元格都包含一個值和鍵(為此創建了一個對象),但是我無法從ArrayList
將值放置到對象中。
不兼容的類型:
String
不能轉換為int
public static void Con(){
ArrayList<Content> arrList1 = new ArrayList<Content>();
ArrayList<ArrayList> arrList2 = new ArrayList<ArrayList>();
//Content yeah = new Content("asdfas","asdfasdf");
for(Content a: arrList1)
//arrList1.add(Content a = new Content("asdf","fasd"));
arrList1.add("oh","yeah");
//arrList1.ge
}
這是對象類
public class Content extends Object{
private String key;
private String value;
private String keyVal;
public Content (String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public String getKeyValue(){
return key+value;
}
public void display(){
System.out.println(this.key+","+this.value);
}
}
我已經想通了。 我用了:
arrList1.add(new Content("9","9"));
抱歉,添麻煩了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.