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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:25:43+00:00 2026-06-15T21:25:43+00:00

We are trying to tokenize a line of input from a file into an

  • 0

We are trying to tokenize a line of input from a file into an ADTList “tokens”. It is reading the information ok, but the first object in the list is being set to NULL. We have tried many changes but cannot figure out where this is occurring. Here is the code:

    //method to covernt lines of input from a file to individual tokens
public static ADTList tokenizer(String input){

    String aToken;                                                      //defining variable to create token
    ADTList tokens = new ADTList();                                     //defining return variable

for (int i = 0; i < input.length(); i++){                           //loop to iterate through input string
        aToken = "";                                                    //clearing variable to hold next string
        if (input.charAt(i) == '(' || input.charAt(i) == ')' ||
                operator(input.charAt(i))){                             //testing for parenthesis or operator
            aToken += input.charAt(i);                                  //concatenating character to string
            tokens.add(aToken);                                         //adding new string to token list
        }else if (Character.isLetter(input.charAt(i))){                 //testing for variable letter
            aToken += input.charAt(i);
    i++;                                                        //moving to next character in string
            if (i < input.length() && Character.isLetterOrDigit(input.charAt(i))){   
                do{                                                     //loop to test for end of variable
                    aToken += input.charAt(i);
                    i++;
                }while (i < input.length() && Character.isLetterOrDigit(input.charAt(i)));    //end of variable condition
            }
            tokens.add(aToken);
            i--;                                                        //decrementing counter variable
        }else if (Character.isDigit(input.charAt(i))){                  //testing for number
    aToken += input.charAt(i);
    i++;
                if (i < input.length() && Character.isDigit(input.charAt(i))){   
                do{                                                     //loop to test for end of variable
                    aToken += input.charAt(i);
                    i++;
                }while (i < input.length() && Character.isDigit(input.charAt(i)));    //end of digit condition
            }
            tokens.add(aToken);
            i--;
        }else{
    //do nothing
        }//end if
}//end loop

return tokens;                                                      //returns tokens list to main
}//endFunction

Here is a snapshot of the output showing the NULL object in the first position:

  • Original function:a1 * ( b + c )
  • Tokenized: null, a1, *, (, b, +, c, ),
  • Infix to Postfix:
  • Postfix to Infix:

  • Original function:( a * b + c

  • Tokenized: null, (, a, *, b, +, c,
  • Infix to Postfix:
  • Postfix to Infix:

Here is the ADTList Class. This is not all, but it does show the add(T item) method that is called by our main project:

public class ADTList<T> implements ListInterface<T>{

//defining internal variables to be used in interface class
private int numItems;
private T array[];

public ADTList(){
    //create an empty array
    array = (T[]) new Object [25];
    //assign 0 to numItems
    numItems=0;
}


public boolean isEmpty(){
// Determines whether a list is empty.
// Precondition: None.
// Postcondition: Returns true if the list is empty,
//                otherwise returns false.
    if (numItems==0){
        return true;
    }else{
        return false;
    }
}

public boolean isFull(){
// Determines whether a list is full.
// Precondition: None.
// Postcondition: Returns true if the list is full,
//                otherwise returns false.
    return numItems==array.length;
}

public int size(){
// Determines the length of a list.
// Precondition: None.
// Postcondition: Returns the number of items that are
//                currently in the list.
    return numItems;
}


public boolean add(T item){
// Adds an item to the end of list.
// Precondition: the item should be inserted in the list.
// Postcondition: If insertion is successful, it returns true,
//               item is at the end of the list,
//               Returns false if the list is full
    if (isFull()){
        return false;
    }else {
        array[numItems]=item;
        numItems++;
        return true;
    }
}
  • 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-15T21:25:44+00:00Added an answer on June 15, 2026 at 9:25 pm

    Sidenote: You have several places where you write code like this:

    if (big_long_test) {
        do {
            something();
        } while(big_long_test);
    }
    

    replace these with

    while (big_long_test) {
        do_something();
    }
    

    The code above does not add a null to the list. Your problem is probably in the ADTList class.

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

Sidebar

Related Questions

I am trying to read from a text file and tokenize the input. I
Hi I'm trying to tokenize a string by loading an entire file into a
I'm trying to get a line as input from the command line. My problem
I am trying to tokenize my data that I get from my text file.
trying to take a line of text and tokenize it into a filename and
i'm trying to generate unigram from a text file. But only the bigram for
I am trying to read data from a file, tokenize it and sort it,
I am trying to tokenize a string but I need to know exactly when
I am trying to read 200,000 records from a file and then use tokenizer
I am trying to tokenize lines in a file using _tcstok. I am able

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.