java - How to get generic list intance's specific item -
java - How to get generic list intance's specific item -
i don't know how specific item generic list instance. suppose have this;
public class column { private string name; private float width; public column(string name, float width) { this.name=name; this.width=width; } public string getname() { homecoming name; }
and class;
public class writecolumn { private list<column> col = new arraylist<>(); public void addcolumn() { col.add(new column("yo", 0.1f)); col.add(new column("mo", 0.3f)); writecolumn(col); public void writecolumn(list<column> col) { string str = ""; (column col1 : col) { str += col1 + " - "; } system.out.println("cols: " + str); } public static void main(string[] args) { writecolumn wc = new writecolumn(); wc.addcolumn(); } }
the output want text part of column not getting it. there simple way of doing ?
i cannot why cannot utilize getname() method?
it should work:
public void writecolumn(list<column> col) { string str = ""; (column col1 : col) { str += col1.getname() + " - "; } system.out.println("cols: " + str); }
java list generics
Comments
Post a Comment