Reputation: 9
How can i return the iterated set values which are of type string from a call method to a future object.do i need to store the iterated vales in a array and return that array or can any one help me out
Upvotes: 0
Views: 9643
Reputation: 425003
Use a Callable<List<String>>
, submit it to an executor, which will return a Future
whose get()
method will return a List<String>
.
ExecutorService executorService = Executors.newSingleThreadExecutor();
Callable<List<String>> task = new Callable<List<String>>() {
public List<String> call() throws Exception {
List<String> list = new ArrayList<String>();
// populate list
return list;
}
};
Future<List<String>> future = executorService.submit(task);
// the list from above, returns once execution is complete
List<String> list = future.get();
Upvotes: 4
Reputation: 33534
Use submit()
method of ExecutorService
which returns Future
Object.
Upvotes: -1