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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:29:31+00:00 2026-05-15T21:29:31+00:00

In methodB I have done a for loop where duplicate names are not displayed.

  • 0

In methodB I have done a for loop where duplicate names are not displayed. If I do this for loop in methodASet it will work. When I try to do this in methodB I get a error message “cannot find symbol – variable name1”. Normally I use this.nameofthemethodheader();, but I now know I can’t do this for TreeSet. Could anyone be kind enough help me here? Here is the code. Thank you. Bear in mind I want to use this for loop that I have done.

public class MyMates  
{

  public MyMates()
  {
    super();    
    names = new TreeSet<String>();  
  }

  public static void methodASet()
  {

    String[] name1 = new String[] {"Amy", "Jose", "Jeremy", "Alice", "Patrick"};
    String[] name2 = new String[] { "Alan", "Amy", "Jeremy", "Helen", "Alexi"};
    String[] name3 = new String[] { "Adel", "Aaron", "Amy", "James", "Alice" };
  }

public static void methodB()
    {


    for (int i = 0; i < name1.length; i++) 
    {
     names.add(name1[i]);
    }
    System.out.println(names);

    for (int i = 0; i < name2.length; i++)
    {
       names.add(name2[i]);
    }   
    System.out.println(names);

    for (int i = 0; i < name3.length; i++)
    {
       names.add(name3[i]);
    }   
    System.out.println(names);


    Dialog.alert("repeated names not selected");
   }
  • 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-15T21:29:32+00:00Added an answer on May 15, 2026 at 9:29 pm

    Ok, try this: (I write it just for making work… in my opinion, it’s an awful code)

    import java.util.Set;
    import java.util.TreeSet;
    
    public class MyMates {
    
    private static String[] name1 = null;
    private static String[] name2 = null;
    private static String[] name3 = null;
    private static Set<String> names;
    
    public MyMates() {
        methodASet();
        names = new TreeSet<String>();
    }
    
    public static void methodASet() {
    
        name1 = new String[]{"Amy", "Jose", "Jeremy", "Alice", "Patrick"};
        name2 = new String[]{"Alan", "Amy", "Jeremy", "Helen", "Alexi"};
        name3 = new String[]{"Adel", "Aaron", "Amy", "James", "Alice"};
    }
    
    public static void methodB() {
    
        for (int i = 0; i < name1.length; i++) {
            names.add(name1[i]);
        }
        System.out.println(names);
    
        for (int i = 0; i < name2.length; i++) {
            names.add(name2[i]);
        }
        System.out.println(names);
    
        for (int i = 0; i < name3.length; i++) {
            names.add(name3[i]);
        }
        System.out.println(names);
    }
    
    public static void main(String[] args) {
        MyMates polop = new MyMates();
        MyMates.methodB();
    }
    }
    

    That prints:

    [Alice, Amy, Jeremy, Jose, Patrick]

    [Alan, Alexi, Alice, Amy, Helen, Jeremy, Jose, Patrick]

    [Aaron, Adel, Alan, Alexi, Alice, Amy, Helen, James, Jeremy, Jose, Patrick]

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

Sidebar

Related Questions

I have an expression like this Expression<Func<IInterface, object>> How do i loop/traverse through all
I have this class and I have a loop that launches multiple threads from
In my services all exposed methods have: try { // the method core is
When I run this method the two properties I have are set to (NULL)
I have done a homework assignment, here is the problem statement: Your program should
I have a client-server style design. What I have done is create a class
Working on making an inventory page for work. I have written a page that
I have run across this method in our code base and wonder what the
I have a method with a for() loop. In that loop, mylabel.text is updated
I have to loop in particluar method which do some task. I have used

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.