Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: return a Co...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 7 of 11 Topic 16078 of 16476
Post > Topic >>

Re: return a Collection (Set or List)

by Lew <lew@[EMAIL PROTECTED] > May 13, 2008 at 07:41 PM

Eric Sosman wrote:
> Roedy Green wrote:
>> On Tue, 13 May 2008 11:37:53 -0700, Mark Space
>> <markspace@[EMAIL PROTECTED]
> wrote, quoted or indirectly quoted someone
>> who said :
>>
>>> Consider substituting two methods for this one.  "getAsList" and 
>>> "getAsSet" Then the caller can indicate which type is desired and 
>>> always receive the correct type.
>>
>> If it is always possible to get as List, why would you ever return
>> anything else?  You can always use a List as a Set.
> 
>     String[] words = { "The", "thing", "about", "Sets",
>         "is", "that", "each", "item", "is", "present",
>         "once", "and", "once", "only." };
>     List<String> list = new ArrayList<String>();
>     Set<String> set = new HashSet<String>();
>     for (String w : words) {
>         list.add(w);
>         set.add(w);
>     }
>     assert list.size() == words.length;
>     assert set.size() == words.length;  // BZZZZT!

Set <String> strangs = new ArrayList <String> (); // BZZZZT!

-- 
Lew
 




 11 Posts in Topic:
return a Collection (Set or List)
thufir <hawat.thufir@[  2008-05-13 11:29:57 
Re: return a Collection (Set or List)
Lew <lew@[EMAIL PROTEC  2008-05-13 08:18:51 
Re: return a Collection (Set or List)
Roedy Green <see_websi  2008-05-13 12:40:58 
Re: return a Collection (Set or List)
Mark Space <markspace@  2008-05-13 11:37:53 
Re: return a Collection (Set or List)
Roedy Green <see_websi  2008-05-13 19:39:07 
Re: return a Collection (Set or List)
Eric Sosman <Eric.Sosm  2008-05-13 16:13:07 
Re: return a Collection (Set or List)
Lew <lew@[EMAIL PROTEC  2008-05-13 19:41:37 
Re: return a Collection (Set or List)
Roedy Green <see_websi  2008-05-14 08:22:59 
Re: return a Collection (Set or List)
thufir <hawat.thufir@[  2008-05-13 22:38:12 
Re: return a Collection (Set or List)
RedGrittyBrick <RedGri  2008-05-14 10:27:23 
Re: return a Collection (Set or List)
Lew <lew@[EMAIL PROTEC  2008-05-14 08:07:30 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 14:45:29 CDT 2008.