Skip to main content

Posts

Showing posts with the label return

How to return multiple objects from a Java method?

I want to return two objects from a Java method and was wondering what could be a good way of doing so? The possible ways I can think of are: return a HashMap (since the two Objects are related) or return an ArrayList of Object objects. To be more precise, the two objects I want to return are (a) List of objects and (b) comma separated names of the same. I want to return these two Objects from one method because I dont want to iterate through the list of objects to get the comma separated names (which I can do in the same loop in this method). Somehow, returning a HashMap does not look a very elegant way of doing so.

return value from Async task in android

one simple question: is it possible to return a variable in Async task? //my async task is in outer class private class myTask extends AsyncTask<Void,Void,Void>{ //initiate vars public myTask() { super(); //my params here } protected Void doInBackground(Void... params) { //do stuff return null; } @Override protected void onPostExecute(Void result) { //do stuff //here! how to return a value??? } } // i execute it from my activity // codes below are from different class than the async task myTask.execute() myvalue = myTask.getvalue() //something like this????