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 6782457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:44:40+00:00 2026-05-26T16:44:40+00:00

Can you help me identify what is wrong in the simple remove from the

  • 0

Can you help me identify what is wrong in the simple remove from the map below (notice output right below it)?

  public class Issue {
  ...

  def allButThis() {
    println "allButThis ..."
    def all = Issue.list()
    println "all is ${all}"
    all.remove(this.id)
    println "all with ${this.id} removed: ${all}"
    return all
  }

   String toString() {return "${id}: ${title}"}

When I run this, I get the following results, i.e. item 2 is not removed as expected

  allButThis ...
  all is [1: Issue-1, 2: Issue-2, 3: Issue-3]
  all with 2 removed: [1: Issue-1, 2: Issue-2, 3: Issue-3]

As far as I can tell, this remove should work, per e.g. http://groovy.codehaus.org/JN1035-Maps, where the “remove” is described one third down the page.

I’m using Grails 1.3.7.

Thanks

P.S. I added my toString() method (above), perhaps I fooled myself.

————- update ———-

I removed my toString() method, and followed Rob’s solution, namely:

  all.remove(this)
  println "all with ${this} removed: ${all}"

which produces:

 all is [momentum.Issue : 1, momentum.Issue : 2, momentum.Issue : 3]
 all with momentum.Issue : 2 removed: [momentum.Issue : 1, momentum.Issue : 3]
  • 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-26T16:44:41+00:00Added an answer on May 26, 2026 at 4:44 pm

    this.id is of type Long and therefore, if you want to remove the n’th item, you need to convert it to an integer. however this is highly dangerous since the id’s entry is not always the n’th entry. remove this item using .findAll({it.id != this.id}) would be more save.

    In this case, I would recommend you to do it like this:

    def allExceptThis = Issue.withCriteria {
       ne("id", this.id)
    }.list();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like information on algorithms that can help identify commonality and differences between
Can someone help me identify what the purpose of this unidentified syntax is. It
Who can help me with regular expression? I need to remove a part of
Who can help me to translate this XML Schema pattern [0-9]+-([0-9]|K) to java regular
Is there anything which can help with msmq monitoring? I'd like to get some
Wondering if anyone can help me with this annoying but trivial (in terms of
Maybe you can help me... I am writing a program in Windows Mobile that
Wonder if anyone can help me understand how to sum up the column of
I hope you can help me. I have a web service that needs to
Hopefully somebody can help me out here. I'm working within an embedded ActionScript2 and

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.