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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:27:13+00:00 2026-05-22T21:27:13+00:00

I need to create an array of array with Strings in java… For example,

  • 0

I need to create an array of array with Strings in java…

For example, I read a file that contain for each column a sport and a player name..like:

The goal at the end it’s for populate a list grouped in section (sports)

hockey,Wayne Gretsky
hockey,Mario Lemieux
baseball,Barry Bonds
baseball,A Rod

I need to create the [][] with this function :

public static String[][] getSportItems(int sectionCount){
    String currentSection="";
    int cnt=0;
    try{

        File file = new File(Environment.getExternalStorageDirectory()
                + "/sports.csv");
        BufferedReader br = new BufferedReader(new FileReader(file));
        String strLine = "";
        while ((strLine = br.readLine()) != null) {
            String[] data = strLine.split(";");
            if(cnt>0){  

            }
            cnt++;
        }
    }catch (IOException e) {
        e.printStackTrace();
    }

}

How I can manage that to create an array for each sport that contain the players associated with the sports.

I’m new in Java… Thanks

  • 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-22T21:27:13+00:00Added an answer on May 22, 2026 at 9:27 pm

    Bonjour Maxime,

    you should better store you data in a hasmap. This allows to associate some value to another.
    For instance, you could define a map that associates a sport to a list of player like this :

    Map<String, List<Player>> mapSportToPlayer = new Hashmap<String, List<Player>>();
    

    or if you don’t have a Player class (but better have one) :

    Map<String, List<String>> mapSportToPlayer = new Hashmap<String, List<String>>();
    

    and to put a player, do like this

    public void addPlayerToSport( String sport, Player player )
    {
       List<Player> listPlayer = mapSportToPlayer.get( sport );
       //first time we associate a player to this sport
       if( listPlayer == null )
       {
           listPlayer = new ArrayList<Player>();
       }//if
       listPlayer.add( player );
    }//met
    

    and to get all people associated with a sport :

    List listPlayer = mapSportToPlayer.get( sport );

    and print them out on console

    for( Player p : listPlayer )
       System.out.println( p );
    

    and then override toString in class player to provide a clear text output of your objects.

    Regards, Stéphane

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

Sidebar

Related Questions

I need to create a dynamic array in Java, but the values type differ
I'm attempting to create an array of strings that represent the directories stored in
I need to create an array of strings, easy enough... the only problem is
I need to create an array by searching a string for occurrences of '['
I need an advice about how to create new string array from 4 different
I need to create an array of arrays. I have been using array_map(null,$a,$b,$c) to
I need to create an array of images in which, every time I tap,
I need to create a big array in my code, I have the values
I need to create a 2D int array of size 800x800. But doing so
I need to create a new line of data within an array where the

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.