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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:07:46+00:00 2026-05-21T21:07:46+00:00

I am trying to extract a linkedlist from an array of linkedlist and am

  • 0

I am trying to extract a linkedlist from an array of linkedlist and am stuck. After extracting this linkedlist, I would need to sum the number of fruits in each basket in each linkedlist. For example, Basket 0 returns 174, Basket 1 returns 147, etc.

I’ve tried using an iterator and listIterator (as well) to extract the number of fruits but I am not getting anywhere. Anyone who can help? Some pointers/hints so I can start coding again.

public class ArrayLinkedList {

    final static int NUM_OF_ROWS = 32767;

    public static void main(String [] args) {

        List[] basket = new List [NUM_OF_ROWS];

        for (int i = 0; i < NUM_OF_ROWS; i++) {
            basket[i] = new LinkedList();
        }

        basket[0].add("1,APPLE,12");
        basket[1].add("2,APPLE,14");
        basket[1].add("3,APPLE,9");
        basket[2].add("4,APPLE,90");
        basket[2].add("5,APPLE,13");

        basket[0].add("1,ORANGE,45");
        basket[0].add("2,ORANGE,19");
        basket[1].add("3,ORANGE,67");
        basket[1].add("4,ORANGE,33");

        basket[0].add("1,BANANA,2");
        basket[0].add("2,BANANA,96");
        basket[1].add("3,BANANA,16");
        basket[1].add("4,BANANA,8");
        basket[2].add("5,BANANA,14");
        basket[2].add("6,BANANA,26");
        basket[3].add("7,BANANA,8");
        basket[3].add("8,BANANA,5");

        for (int i = 0; i < 5; i++) {
           System.out.println("Basket " + i + ": " + rows[i].toString());
        }

    }

}
  • 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-21T21:07:47+00:00Added an answer on May 21, 2026 at 9:07 pm

    You should not use a string to store multiple information. This would force you to parse the string each time you want to get a part of the information. I don’t know what "1,APPLE,12" represents, but you should use an object instead of this string :

    public class Item {
        private int something;
        private String fruitName;
        private int numberOfFruits;
    
        public Item(int something, String fruitName, int numberOfFruits) {
            this.something = something;
            this.fruitName = fruitName;
            this.numberOfFruits = numberOfFruits;
        }
    
        public int getSomething() {
            return this.something;
        }
    
        public String getFruitName() {
            return this.fruitName;
        }
    
        public int getNumberOfFruits() {
            return this.numberOfFruits;
        }
    }
    

    And then, your array of baskets can be built like this :

    List<Item>[] basket = new List<Basket>[NUM_OF_ROWS];
    
    for (int i = 0; i < NUM_OF_ROWS; i++) {
        basket[i] = new LinkedList<Item>();
    }
    
    basket[0].add(new Item(1, "APPLE", 12));
    basket[1].add(new Item(2, "APPLE", 14));
    // ...
    

    Then, you may iterate over one of the baskets and compute the total number of fruits easily :

    int totalNumber = 0;
    for (Item item : basket[0]) {
        totalNumber += item.getNumberOfFruits();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to extract the number of specials unlocked at a venue from
hi i'm trying to extract values from this tagged file here is the file
I am trying to extract an XML node from a URI reference. This URI
I am trying to extract the Interface from an array created from an SNMP
I am trying to extract specific index values from an array, and place them
I am trying to extract data from this String: Hello there. Blah blahblah blah
im trying to extract the most common YEAR from an array of DateTime objects
I'm currently trying to extract data from a table, and am using this: $online
I'm trying to extract the overall comments number from a web page using Jsoup.
Im trying to extract a YouTube link from just random text. e.g. This is

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.