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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:15:57+00:00 2026-06-02T19:15:57+00:00

Below is the program I have for reading the .csv file and printing the

  • 0

Below is the program I have for reading the .csv file and printing the output, but I am not able to achive the below functionality as mentioned in my input and output. I basically want to have the user ID listed separately if it’s avaialble in 2 different groups.

My input would be something like:

User ID       Group

ABC           Group1   
DEF           Group2
ABC           Group3
GHI           Group4

Since ABC is available in 2 different groups, I need the output as:

ABC     Group1
ABC     Group3

Can you please help?

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.StringTokenizer;

public class dumpRead {
    public static void main(String[] args) {
        try {

            //csv file containing data
            String strFile = "C:/Tracker/read/data.csv";

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

            //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++;
                    System.out.println("Token # " + tokenNumber 
                    + ", Token : "+ st.nextToken());
                }

                //reset token number
                tokenNumber = 0;                        
            }
        }
        catch(Exception e) {
            System.out.println("Exception while reading csv file: " +     e);                   
        }
    }
}
  • 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-02T19:15:59+00:00Added an answer on June 2, 2026 at 7:15 pm

    Parse all the user id’s and put it in a HashMap>

    For each userid, check if it is already there in the hashmap, if it is already there, then get the corresponding Set and add it to the end of the list.
    if hashmap does not contain the user, then create a new HashSet and add the group

    Note: The idea behind HashSet, is it will ignore duplicates

    The psuedo code will be something like this,

    for(string user: users)
    {
      if(hashmap.contains(user))
        {
           HashSet<Sting> usergroups = hashmap.get(user);
           usergroups.add(group);
        }
       else
        {
          HashSet<String> groups = new HashSet<String> ();
           groups.add(group);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Enumeration as shown in below program public class Test { public
I have a program shown below: Socket receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); EndPoint
Below I have written a sample program that I have written to learn about
I have the below command line arguments set for the program. argument proc is
I have below five Integer variables and during the program, they are assigned some
I have a C program like the one below. I am trying to write
Below, I have a simple program which uses the CImg library (http://cimg.sourceforge.net/) which iterates
I have wrote the code below which was taken from Java How to program
As you can see below, I have Parallel.For loop. If run the program while
According to the tutorial I am reading, the program below displays Hello Ima Reader.

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.