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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:35:54+00:00 2026-05-21T00:35:54+00:00

I am trying to compare an array of strings (a csv file of stock

  • 0

I am trying to compare an array of strings (a csv file of stock market symbols that was imported into an arraylist and then converted to an array) but it does not seem to be working. Am I not comparing it to the correct data type or something? Here is my code:

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.ArrayList;

public class search
{
    public static void main(String[] args)
    {
        try
        {
            //csv file containing data
            String strFile = "companylist.csv";

            //create BufferedReader to read csv file
            BufferedReader br = new BufferedReader(new FileReader(strFile));
            String strLine = "";
            StringTokenizer st = null;
            int lineNumber = 0, tokenNumber = 0;

            //create arraylist
            ArrayList<String> arrayList = new ArrayList<String>();

            //read comma separated file line by line
            while ((strLine = br.readLine()) != null)
            {
                lineNumber++;

                //break comma separated line using ","
                st = new StringTokenizer(strLine, ",");

                while (st.hasMoreTokens())
                {
                    //display csv values
                    tokenNumber++;
                    arrayList.add(st.nextToken());
                    //System.out.println("Line # " + lineNumber + ": "+ st.nextToken() + " " + st.nextToken());
                } //end small while

                //reset token number
                tokenNumber = 0;

            } //end big while loop

            //send csv to an array
            Object[] elements = arrayList.toArray();
            /*
            for(int i=0; i < elements.length ; i++)    {    
            System.out.println(elements[i]); 

            } */
            Scanner input = new Scanner(System.in);
            System.out.print("Enter Ticker symbol");
            String sym = input.next();

            for (int i = 0; i < elements.length; i++)
            {
                if (elements[i].equals(sym))
                {
                    System.out.println("match");
                }
            }
        }
        catch (Exception e)
        {
            System.out.println("Exception while reading csv file: " + e);
        }

    }//end main
}//end class

Any help is greatly appreciated

  • 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-21T00:35:55+00:00Added an answer on May 21, 2026 at 12:35 am

    First, make sure your elements are filled properly. For example – without any whitespaces (use trim())

    Then you can use something simpler: elementsList.contains(sym).

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

Sidebar

Related Questions

I'm trying to use simpletest to compare two numeric strings, one from an array
I'm trying to loop through an array (compare Addr), and find the matching Strings
How would i implement this?Im trying to compare a array of c strings to
I am trying to compare a string to an array of strings and add
I'm trying to compare text in an unordered list to an array that I
I'm trying to compare two arrays and get only the values that exist on
Trying to compare and print only members with Inactive status. The problem is that
I am trying to compare a list of forbidden folders read from a file.
I am trying to compare two variables in which are usually strings. These variables
I am trying to sort an array of strings, but it's not sorting anything....

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.