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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:49:15+00:00 2026-06-17T18:49:15+00:00

I have implemented a program that stores sets within a Linkedlist . When I

  • 0

I have implemented a program that stores sets within a Linkedlist. When I print out the linked lists, I get, for example, [1,2,3,4,5].

What I want is to change the square brackets to braces e.g. ‘{‘ & ‘}’

I can’t use string manipulations so I MUST override the toString method.

I am clueless on how to do this other than the fact I know i must create a subclass. It’s the method itself that baffles me.

public class outputSets
    {    
        @SuppressWarnings({ "unchecked", "rawtypes", "unused" })
        public static void main(String args[]) 
        {    
        LinkedList x0 = new LinkedList();
        LinkedList x1 = new LinkedList();
        LinkedList x2 = new LinkedList();
        LinkedList x3 = new LinkedList();
        LinkedList x4 = new LinkedList();
        LinkedList x5 = new LinkedList();
        LinkedList x6 = new LinkedList();

        x0.add(new Integer(8));

        for(int i=1; i<8; i++)
        {
            x1.add(new Integer(i));
        }

        x1.add((x0.getFirst()));

        x2.addAll(x1);
        x2.add(new Pair(1, x1));

        x3.add(new Pair(x2,x1));

        //x4.addAll(tree.union(x3, x2));

        //x5.add(tree.difference(x4, x1));

        //x6.add(tree.intersection(x4, x1));
        /*
        Iterator i0 = x0.listIterator();
        Iterator i1 = x0.listIterator();
        Iterator i2 = x0.listIterator();
        Iterator i3 = x0.listIterator();
        Iterator i4 = x0.listIterator();
        Iterator i5 = x0.listIterator();
        Iterator i6 = x0.listIterator();
        */

        System.out.print(x0.getFirst());
        System.out.println();
        SetArray(x1);
        System.out.println();
        SetArray(x2);

        System.out.println();
        System.out.println();
      }


    @SuppressWarnings("rawtypes")
    private static void SetArray(LinkedList x0)
    {
        for(int index=0; index < x0.size() ; index++)
        {
            if (index == 0)
            {
                System.out.print(x0.get(index));
            }
            else
            {
                System.out.print(", " +
                        "" + x0.get(index));
            }
        }

    }
}
  • 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-17T18:49:17+00:00Added an answer on June 17, 2026 at 6:49 pm

    The output is completely dependent on the implementation of AbstractCollection.toString() – which LinkedList (and most other collections except maps) inherits. This implementation looks like this (slightly simplified):

    public String toString() {
        Iterator<E> it = iterator();
        if (! it.hasNext())
            return "[]";
    
        StringBuilder sb = new StringBuilder();
        sb.append('[');
        for (;;) {
            E e = it.next();
            sb.append(e);
            if (! it.hasNext())
                return sb.append(']').toString();
            sb.append(", ");
        }
    }
    

    Having this as a guideline it should be pretty straightforward for you to create your own implementation that does not include square brackets. You can either create your own collection that overrides toString() or have a separate utility method taking your LinkedList input as an argument (in that case obviously replace iterator() with input.iterator()).

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

Sidebar

Related Questions

I have a program that is been implemented in C++ which I now want
my program creates expandable Lists, and I have implemented swipes- but I cant figure
I have implemented Facebook into my app but now I find that whenever I
I implemented a program about calculating the stock values comparing that value in the
All, I have Core Data implemented in my program to store customer information. Let's
I have a simple plugin architecture for my program that uses an interface to
I want to write a program in Objective-c that grabs some sports stats off
I'll take a real example I have to implement in a program I'm coding:
I have a program in which I want to be able to store certain
I have a occasionally connected application where there is a server that stores information

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.