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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:36:03+00:00 2026-06-13T12:36:03+00:00

I am creating a demo shopping cart in android for this i am using

  • 0

I am creating a demo shopping cart in android for this i am using Application class for saving data. I am unable to delete data from linkedlist. I am calling removeItem() function for android activity for removing selected item from the list but it is not working any one can help me.

    package in.co.santoshsharma.bookshopping;

import java.util.LinkedList;

import android.app.Application;
import android.content.res.Configuration;

public class GlobalData extends Application{
    private String email;
    private String itemName;
    private int itemQuantity;
    private int itemCost;

    public GlobalData(){

    }
    public  GlobalData(String iName,int iQunt,int iCost) {
        // TODO Auto-generated constructor stub
        this.itemCost=iCost;
        this.itemName=iName;
        this.itemQuantity=iQunt;

    }




    public void setEmail(String mail)
    {
        this.email=mail;
    }

    public String getEmail()
    {
        return email;
    }
    public String getItemName()
    {
        return itemName;
    }

    public int getItemCost()
    {
        return itemCost;
    }

    public int getItemQunt()
    {
        return itemQuantity;
    }



    LinkedList<GlobalData> list = new LinkedList<GlobalData>();

    public void setList(String iName,int iQunt,int iCost)
    {
        list.add(new GlobalData( iName, iQunt, iCost));
    }

    public LinkedList<GlobalData> getList()
    {
        return list;
    }
    public void removeItem(String iName,int iQunt,int iCost)
    {
        for(GlobalData data:list)
        {
            if(data.getItemName().equals(iName))
            {
                list.remove(itemName);
                //list.remove(iCost);
                //list.remove(iQunt);
            }
        }
    } 



}
  • 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-13T12:36:04+00:00Added an answer on June 13, 2026 at 12:36 pm

    First, override equals() method and use itemName attribute for the comparison

    @Override
    public boolean equals(Object o) {
      if (o == null) return false;
      if (itemName == null) return false;
      if (o instanceOf String) return itemName.equals(o);
      else if (o instanceOf GlobalData) return ((GlobalData) o).itemName.equals(this.itemName);
      else return false;
    }
    

    Then, change your removeItem() method

    public void removeItem(String iName) {
      list.remove(iName);
      // or uncomment line below to completely remove all matching elements
      // for (;;list.remove(iName)) {}
    }
    

    According to http://docs.oracle.com/javase/6/docs/api/java/util/LinkedList.html#remove(java.lang.Object) remove() method of a LinkedList will call the equals() method of the supplied Object and compare it with every element in the list.

    Hope this helps 🙂

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

Sidebar

Related Questions

i am creating a demo application using spring mvc 3.0.I have to apply the
I am creating a demo application using Spring mvc 3.0.Now i wants to connect
I am beginner php Programmer, i am creating a shopping cart application, I have
I am creating pdf File using the screen shots taking programatically from webView. But
We are creating an installer using WIX 3.6 for a Silverlight/WCF application. We require
Hey I am creating a demo to display the benefits of using a pivotviewer.
I want com.google.android.maps library. I am just creating a demo for Map on android
By creating datastore models that inherit from the Expando class I can make my
i am creating media recorder demo application. for that i have take two button
I am creating a fullscreen demo application (demo = not production, so hacky code

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.