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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:03:17+00:00 2026-05-25T06:03:17+00:00

I had been given an assignment to implement ArrayList and LinkedList without using generics.

  • 0

I had been given an assignment to implement ArrayList and LinkedList without using generics. The problem is with the insertnode() method. Though I try to read from commandline using a scanner, the method returns without waiting.

import static java.lang.System.out;
import java.util.Scanner;
class Arraylist
{
public static final int LIST_SIZE=30;
static Scanner input = new Scanner(System.in);
static Object list[];
static int top = -1;
static int typeoflist; 
public static void displaymenu()
{
    int choice;
    do{
        out.print("\n Basic operations on a linked list:");
        out.print("\n 1. Create list  \n 2. Insert node \n 3. Delete node  \n 4. Modify node \n 5. Search value \n 6. Print list\n Else. Exit \n Choice:");
        choice = input.nextInt();
        switch(choice)
        {
            case 1:
                list = createlist();
                break;
            case 2:
                insertnode();
                break;
            case 3:
                //deletenode();
                break;
            case 4:
                //modifynode();
                break;
            case 5:
                //searchnode();
                break;
            case 6:
                printlist();
                break;
            default:
                return;
        }       
    }while(true);
}   
public static Object[] createlist()
{
    int typeoflist;
    out.println("Enter your choice of list datatype: \n 1. int \n 2. float \n 3. char \n 4. String \n 5. UserDefined \n Choice:");
    typeoflist = input.nextInt();
    switch(typeoflist)
    {
        case 1:
            list = new Integer[LIST_SIZE];
            break;
        case 2:
            list = new Float[LIST_SIZE];
            break;
        case 3:
            list = new Character[LIST_SIZE];
            break;
        case 4:
            list = new String[LIST_SIZE];
            break;
    }
    return (Object[])list; 
}
public static void insertnode()
{
    Object o;
    top++;
    out.println("Enter the value to insert:");
    switch(typeoflist)
    {
        case 1:
            o = (Integer)input.nextInt();
            list[top] = o;
            break;
        case 2:
            o = (Float)input.nextFloat();
            list[top] = o;
            break;
        case 3:
            //o = (Character)input.next();  //
            //list[top] = o;
            break;
        case 4:
            o = (String)input.next();
            list[top] = o;
            break;
    }   
}   
public static void printlist()  
{
    for(int i =0; i<top; i++)
    {
        out.println(list[i]);
    }
}   
public static void main(String[] args)
{
    displaymenu();
}
}
  • 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-25T06:03:18+00:00Added an answer on May 25, 2026 at 6:03 am

    Hint: typeoflist in createList() is hiding the static member variable.

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

Sidebar

Related Questions

From previous experience I had been under the impression that it's perfectly legal (though
I've written a QuickSort algorithm based off pseudo-code that I had been given. I've
I had been programming under the assumption that, when calling a method in C#
I had been trying to implement OnTouchEvent so I can react when an user
I had been happily coding along on a decent sized solution (just over 13k
I had been steering away from C# for a while, because it was just
I had been wondering for quite some time on how to manager memory in
I had been asked to build crystal reports for an application, i used the
I had been working on server side(c#) for a couple of years. But now
I've had been hearing about test driven development for a couple years now, and

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.