Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6952495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:21:23+00:00 2026-05-27T14:21:23+00:00

Let’s consider the following example. Writing API which has public method which returns Collection

  • 0

Let’s consider the following example.

Writing API which has public method which returns Collection of unique Objects.
I believe that is is good to write return type of that method Set to show to user that the items are unique.
In case when these items are unique and ordered is it a right idea to write return type LinkedHashSet or it is good to be Collection?

I know collections which are unique and sorted. I what to know it is a good idea to set public method’s return type class(TreeSet,SortedSet,LinkedHashSet). In in terms of oop.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:21:24+00:00Added an answer on May 27, 2026 at 2:21 pm

    I’d recommend against returning LinkedHashSet (unless you have a very good justification for it). If you return Set, you can change the Set implementation as you see fit, e.g. HashSet, TreeSet etc

    In this case, I think your suggestion of returning Set is a good one as it does indicate that the items are unique. This also indicates that contains will generally be fast (O(1) or O(log n)).

    On the other hand, Collection is very generic, but all it tells the caller is that it is a plain old group of somethings without any special constraints on ordering or uniqueness. Specifying Set means that there isn’t any confusion about uniqueness, and you can use it anywhere where a Collection can be used anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's consider the following 3 code lines: struct stat buffer; status = lstat(file.c_str(), &buffer);
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's consider the following scenario: I've a master table with a detail table. The
Let's say I'm writing a Windows Forms (.NET Framework 3.5) application which shows the
Let's say for example i have URL containing the following percent encoded character :
Let's say I'm writing a PHP (>= 5.0) class that's meant to be a
Let's say I can call a method like this: core::get() . What is the
Let say I have the following desire, to simplify the IConvertible's to allow me
Let's take a common example how a haskell function can be called from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.