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

  • Home
  • SEARCH
  • 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 3666596
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:53:59+00:00 2026-05-19T01:53:59+00:00

Have a SortedSet where I need a specific slice of records based on a

  • 0

Have a SortedSet where I need a specific slice of records based on a specific element in the list.

Example:
In the code below, challengeDTO.members is a SortedSet (TreeSet implementation)

I know the location of one member

def memberRank = challengeDTO.members.findIndexOf { it.member.id == membership?.id} + 1

If the memberRank is 66, I want to get a slice of members 60 through 70 ranks.

challengeDTO.members[60..69] won’t work because it’s a set

Ideas? Suggestions?

Member implementation:

class ChallengeMemberDTO implements Comparable<ChallengeMemberDTO> {

  ChallengeMember member
  Integer total
  String name
  String teamName

  int compareTo(ChallengeMemberDTO t) {
    if (total == t.total) {  // the sortedset will remove duplicates based on same total, which is not desireable
      return name.compareTo(t.name)
    }
    else {
      return t.total.compareTo(total)
    }
  }
}
  • 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-19T01:53:59+00:00Added an answer on May 19, 2026 at 1:53 am

    Try:

    (challengeDTO.members as List)[60..69]
    

    Under the covers the Groovy as List type conversion creates an instance of ArrayList and calls addAll, passing your SortedSet. As per the java.util.List JavaDoc addAll “appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection’s iterator”. In the java.util.SortedSet JavaDoc it states that “the set’s iterator will traverse the set in ascending element order.”

    So the order of the list will match the order of the SortedSet.

    If you’re interested, you can take a look at the method in the Groovy source code:

    org.codehaus.groovy.runtime.DefaultGroovyMethods.asList(Collection<T> self)

    EDIT:

    For the sake completeness, in Java you could do the following. It’s just what the Groovy code above does under the covers:

    SortedSet<ChallendMemberDTO> memberSet = challengeDTO.getMembers();
    List<ChallengeMemberDTO> membersPage = new ArrayList<ChallengeMemberDTO>(memberSet).subList(60, 70);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SortedSet defined this way: SortedSet<RatedMessage> messageCollection = new TreeSet<RatedMessage>(new Comp()); and
I have a service that produces as result a SortedSet object. I need to
I have found this example on StackOverflow: var people = new List<Person> { new
I have a SortedSet (specifically a TreeSet ) containing updates. An update is something
Have you guys had any experiences (positive or negative) by placing your source code/solution
I need a sorted set of objects and am currently using the TreeSet .
Have I correctly added an element to a hashTable? Flows flows = new Flows(sIP,dIP);
i have a input tag which is non editable, but some times i need
I'm trying to use .NET 4's SortedSet<T> collection. It seems to have everything I
I have something like this: public class CPerson: INotifyPropertyChanged public class CPeople: SortedSet<CPerson> public

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.