Reputation: 17
i am new to andoird and i am using list with custom defined class but i am not sure how to add my key value pair in this list here is my code
public class Pair<K,V> {
private K k;
private V v;
public Pair(K k,V v)
{
this.k=k;
this.v=v;
}
public K getK()
{
return k;
}
public void setK( K k)
{
this.k=k;
}
public V getV()
{
return v;
}
public void setV(V v)
{
this.v=v;
}
}
and
List<Pair<String,String>> pl = new ArrayList<Pair<String,String>>();
I tried
pl.add(Pair("name","ahsen"));
pl.addAll(Pair("name","ahsen"));
but its not working
Upvotes: 0
Views: 134
Reputation: 2687
am i missing something or its just missing new operator ?
pl.add(new Pair("name","ahsen"));
pl.addAll(new Pair("name","ahsen"));
Upvotes: 1