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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:57:20+00:00 2026-06-04T03:57:20+00:00

There are too many time I encounter the need to write an adder/remover methods

  • 0

There are too many time I encounter the need to write an adder/remover methods for lists:

public void addSomething(Something something){
    somethings.add(something);
}

public void removeSomething(Something something){
    somethings.remove(something);
}

If I got it right, then Eclipse templates can support auto complete… for example, if I have a:

Vector<Something> somethings=new Vector<Something>();

I would like the template to add the method to the Auto-Complete of Eclipse, and would auto complete the entire method:

public void addSomething(Something something){
    somethings.add(something);
}

when I type “add” + (Ctrl + Space)…

Any idea how to accomplish something like this… perhaps point me to a reading material specific to this sort of subject.

** UPDATE **

Well, this is what I have so far:

public final void add${type:elemType(collection)}(${type} ${varName:newName(type)}) {
    ${collection}.add(${varName}); 
}

Here is the problem though, If I type “add” + (Ctrl + Space):

In the class level, and the collection is declared as a field, I get an empty variable as a collection.

public final void addtype(type type) {
    collection.add(type);
}

In the method level, and the collection is declared as a field, I get an empty variable as a collection.

public final void addtype(type type) {
    collection.add(type);
}

In the method level, and the collection reference is a local variable of the method I get the correct syntax, but the add method is inside the other method.

public void method(...) {
    public final void addSomething(Something something) {
        this.somethings.add(something);
    }
}

Which means I don’t get field level reference, how can I obtain it?

** UPDATE 2 **

This also gives the same result:

public final void add${type:elemType(collection)}(${type} ${varName:newName(type)}) {
    ${collection:field(java.util.Collection)}.add(${varName}); 
}

public final void remove${type:elemType(collection)}(${type} ${varName:newName(type)}) {
    ${collection:field(java.util.Collection)}.remove(${varName}); 
}

Thanks,

Adam.

  • 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-06-04T03:57:22+00:00Added an answer on June 4, 2026 at 3:57 am

    I’ve finally used the following:

    public final void add${type:elemType(collection)}(${type} ${varName:newName(type)}) {
        ${collection:field(java.util.Collection)}.add(${varName}); 
    }
    
    public final void remove${type:elemType(collection)}(${type} ${varName:newName(type)}) {
        ${collection:field(java.util.Collection)}.remove(${varName}); 
    }
    

    I create this with in a method, and cut it to the class level… 🙂

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

Sidebar

Related Questions

EDIT: Too many edits :doh: I have identified the problem this time. There is
There are too many options for creating projects in XCode, But When we select
There are too many tutorials out there on monads that say... Look! here is
There is a Debian g++-4.4 package, but it's not Ubuntu. There are too many
I'm using VS2010 every day, and haven't noticed it before. There is too many
There seems to be too many attributes/parameters in CSS... I want to know all
Q1: Is there something like too much ajax?? Explanation: I have been seeing programmers
When I run my test code for EventMachine, I found there are too many
There are too many types of data streaming classes in the Java API. I
I had a discussion with some colleagues mentioning that there are not too many

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.