wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Returning the individual elements of a list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Returning the individual elements of a list" Watch "Returning the individual elements of a list" New topic
Author

Returning the individual elements of a list

Iain Emsley
Ranch Hand

Joined: Oct 11, 2007
Posts: 60
I'm trying to work out some code for a scheduling system which takes an id, works out if this id is an person or a group. If its a person, then easy to return but I'm having some issue regarding the return of the individuals in a group. (Its a hack around an issue in the calDAV specs.) My code queries a database via two methods (one for individuals and one to return a list of individuals in a group). I've iterated through the returned list and placed into the uri string but I cannot then return all the users to another method which works on another scheduling task - I either get the first or the last. Is there a sensible way around this (I'm trying to debug some code which relies on returning a list but its making the job harder than it need be and the code less maintainable)?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38066
    
  22
Difficult to understand what you want, but you can only return one thing from a method. You appear to get a String from caladdrToUsers and a List<String> later on.

If you have an ID you can obtain, you ought to be able to pass/return it with the flag for individual/group.
Iain Emsley
Ranch Hand

Joined: Oct 11, 2007
Posts: 60
What I want to do is to take the List and then return each of the IDs contained in it if it is a group. The method above takes a string then calls the caladdToUser(s) methods to work out if the string is group or an individual. What I'd like to do is to then take the returned list (morelists), iterate through it and return the each id inside it (passed back to uri). As per my post, I can either get the first or the last but I'd also like the bits in between.

The schedule relies on having the individual id not the group, hence trying to do this.
[Edited to add second paragraph]
[ August 22, 2008: Message edited by: Iain Emsley ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38066
    
  22
There is something very peculiar in that method; you are getting a String from calladdrToUser() and later a List from the same method. I am surprised that will compile. What does that calladdrToUser() method return?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Originally posted by Iain Emsley:
I've iterated through the returned list and placed into the uri string but I cannot then return all the users...
Your method is designed to return a String. That isn't a good choice if it is supposed to return "all the users". Unless you can cram them all into a String in some way, which I don't recommend unless somebody else has required you to return a String and you don't have the choice of returning a List of Strings.

Which is what you should do. Return a List<String>, not a String. Inside the method, create an empty list. If you're iterating through a group, then add the uri's to the list. If you have an individual, add that uri to the list. Then return that list as the value of the method.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Returning the individual elements of a list
 
Similar Threads
Trying to implement a mail queue in JavaMail using ExecutorService
Trying to create a threaded pool in JavaMail to deal with bulk mailing
Getting JavaMail Mailer to email one address at a time
Problem with Spring Web Flow
Navigation Problem