here is my problem.
I have a class A that has a string of names and int of numbers which is placed into an ArrayList of another class.
Task:- what i need to do is get the first name from index(0) from the arraylist and return it as a string.
public class A
{
private String name;
private int num;
public A(String aName, int bNum)
{
name = aName;
num = bNum;
public String getName()
{return name; }
public int getNum()
{return num;}
}
}
//class b inserts elements of class a into arraylist
public class b
{
private ArrayList<A> myList;
}
public b()
myList = new ArrayList<A>;
public void addAll(A all)
{ myList.add(all);}
//get method required for issue above.
Check if the the your list has any item present or no. If present, retrieve the first element and get the name for it to return otherwise return null or empty string as desired.
EDIT:
Where you are calling this method, you may write as:
Hope this helps.