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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:08:46+00:00 2026-05-25T13:08:46+00:00

I am writing a CSVParser program that seperates words at commas. I am currently

  • 0

I am writing a CSVParser program that seperates words at commas. I am currently trying to find and record the longest word that appears in the file. Here is my class.

import csv.CSVParser;
import java.io.*;
import java.util.*;

public class RecordFormatter {

public static void main (String[] args) {
       CSVParser parser = new CSVParser(new File (args[0]));
       while (parser.hasNextLine()) {
              ArrayList<String> ls = parser.getNextLine();
              for (int i = 0; i<ls.size(); i++) {
                   System.out.print("|" + ls.get(i) + " ");
                   }
              System.out.print("|");
              System.out.println();
       }
      CSVParser parser1 = new CSVParser(new File (args[0]));
      ArrayList<Integer> maxCol = new ArrayList<Integer>();
      while (parser1.hasNextLine()) {
            ArrayList<String> ls1 = parser1.getNextLine();
            for (int i = 0; i<ls1.size(); i++) {
                 maxCol.add(ls1.get(i)); //Here is where my bug occurs.
            }
      }

}

}

I have created two CSVParsers and am trying to use the second of the two to record the length. I tried (as you can see above) storing the int length value of each word into another Arraylist, but I can’t seem to get it to work. Any help would be much 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-25T13:08:47+00:00Added an answer on May 25, 2026 at 1:08 pm

    Without giving the solution, since this is homework…

    Notice that you are keeping every length value rather than comparing the current length against a previous value to determine if it is longer and only then keeping it.

    Seems like you need just a single maxLength Integer (or int) rather than a list since you just want the longest single word.

    If you wanted the longest word per line, a List might then be appropriate.

    Another option would be to use a SortedList and get the largest value (last value) in the list.

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

Sidebar

Related Questions

Writing a simple program that will find exact duplicate files on my computer, but
Writing my first Linq application, and I'm trying to find the best way to
Writing a Jabber client that uses Twisted Words. I would like to know an
Writing text to .txt files using actionscript. how? i couldn't find anything about that
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
Writing documentation in html requires some code examples. What to do with characters that
Writing a python program, and I came up with this error while using the
Writing a .NET DLL how do I find Application.ProductName ? EDIT: Obviously, importing Windows.Forms
Writing a sound control applet with GUI that communicates with a device via USB.
Writing an app that will include the ability to decompress zip and rar files.

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.