let’s say I have
class Dummy {
String a, b;
public Dummy(String a, String b) {
this.a = a;
this.b = b;
}
public String toString(){
return a+b;
}
public String getA() {
return a;
}
public String getB() {
return b;
}
}
i would like to have
List<Dummy> myList = new ArrayList<Dummy>() {{
add(new Dummy("test", ""));
add(new Dummy("boo", "o"));
}};
System.out.println( myList.toString());
System.out.println( myList.getAs()); //should return ["test", "boo"]
System.out.println( myList.getBs());//should return ["", "o"]
If you see what I mean
probably have to create class extending ArrayList<Dummy> ?
edit:
seems good like that
class Dummy {
String a, b;
//...
public static String toAString(List<Dummy> l){
String s="";
for (Dummy d : l){
s+=d.a;
}
return s;
}
}
edit2:
I will have just 2 Strings in Dummy, is it better doing a ArrayList<String []> rather ? in terms of memory
Define first-class functions corresponding to
getAandgetB. I am usingFunctionfrom Guava for that.This is how you can use it: (
Iterablesbelow is also from Guava).