I wrote some code to return me an array of objects. How do I save those objects in the called method?
public Ticket[] getOpenTicket() {
int ticketcount = 0;
for (int i = 0; i < ticket.length; i++) {
if (ticket[i] != null && ticket[i].getResolvedBy() == null) {
ticketcount = ticketcount + 1;
// System.out.println("Ticket raised by : " +
// ticket[i].getTicketno());
}
}
Ticket[] opentickets = new Ticket[ticketcount];
for (int i = 0; i < ticket.length; i++) {
if (ticket[i].getResolvedBy() == null) {
opentickets[i] = ticket[i];
}
}
return opentickets;
}
This is the called function from where I am calling openticket:
TicketDaoMemImpl tdmi=new TicketDaoMemImpl();
Ticket [] obj1=tdmi.getOpenTicket();
Thanks
ticketwhich is presumably an array but it is never declared (unless you have it declared as a global array somewhere in your class?) As posted, this wouldn't compile.