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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:28:53+00:00 2026-05-14T22:28:53+00:00

If I have a 2D array that is arranged as follows : String X[][]

  • 0

If I have a 2D array that is arranged as follows :

  String X[][] = new String [][] {{"127.0.0.9", "60", "75000","UDP", "Good"},
                              {"127.0.0.8", "75", "75000","TCP", "Bad"},
                      {"127.0.0.9", "75", "70000","UDP", "Good"},
                      {"127.0.0.1", "", "70000","UDP", "Good"},
                      {"127.0.0.1", "75", "75000","TCP", "Bad"}
                                   };

I want to know the frequency of each value .. so I27.0.0.9 gets 2. How can I do a general solution for this ? In Java or any algorithm for any language ?

  • 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-14T22:28:54+00:00Added an answer on May 14, 2026 at 10:28 pm

    It looks like you need a custom data type to encapsulate each row rather than using a String[][], but to answer your question more directly, you can use a Map<String,Integer> for each column. A HashMap<String,Integer> can be expected to do this in optimal time.


    Here’s a snippet to demonstrate the idea:

    import java.util.*;
    
    public class Frequency {
        static void increment(Map<String,Integer> map, String key) {
            Integer count = map.get(key);
            map.put(key, (count == null ? 0 : count) + 1);
        }
        public static void main(String[] args) {
            String table[][] = new String[][] {
                {"127.0.0.9", "60", "75000","UDP", "Good"},
                {"127.0.0.8", "75", "75000","TCP", "Bad"},
                {"127.0.0.9", "75", "70000","UDP", "Good"},
                {"127.0.0.1", "", "70000","UDP", "Good"},
                {"127.0.0.1", "75", "75000","TCP", "Bad"}
            };
            final int M = table.length;
            final int N = table[0].length;
            List<Map<String,Integer>> maps = new ArrayList<Map<String,Integer>>();
            for (int i = 0; i < N; i++) {
                maps.add(new HashMap<String,Integer>());
            }
            for (String[] row : table) {
                for (int i = 0; i < N; i++) {               
                    increment(maps.get(i), row[i]);
                }
            }
            for (Map<String,Integer> map : maps) {
                System.out.println(map);
            }
            System.out.println(maps.get(0).get("127.0.0.9"));
        }
    }
    

    This produces the following output: each line is a frequency map for each column:

    {127.0.0.9=2, 127.0.0.8=1, 127.0.0.1=2}
    {=1, 60=1, 75=3}
    {75000=3, 70000=2}
    {UDP=3, TCP=2}
    {Good=3, Bad=2}
    2
    

    Note: if you don’t care about mixing values from all columns together, then you only need one Map, instead of a List<Map> one for each column. This would make the design even worse, though. You really should encapsulate each row into a custom type, instead of a having everything mixed as String[][].

    For example some of those columns really looks like they should be an enum.

    enum Protocol { UDP, TCP; }
    enum Condition { Good, Bad; }
    //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Officially globbing and regular expressions are not supported: http://www.robotstxt.org/robotstxt.html but… May 16, 2026 at 12:29 pm
  • Editorial Team
    Editorial Team added an answer I got it working! I have the following code in… May 16, 2026 at 12:29 pm
  • Editorial Team
    Editorial Team added an answer What you are looking for is a Javascript image carousel.… May 16, 2026 at 12:29 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a messy tree multidimensional array that I want to do the following
Let's say I have a tab-delimited text file that contains data arranged in columns
I have one array that contains some settings that looks like basically like this:
I have an array that is like this: unsigned char array[] = {'\xc0', '\x3f',
I have an array of Image URl's from that array i have displayed my
I have an array, $scans. I want to query MySQL with all the values
I have the array example below that I am using to dynamically create an
I have an inline assembler loop that cumulatively adds elements from an int32 data
I have this array: $array = array('a' => 'apple' , 'c' => 'cat', 'ar'
Hi I have an array of strings separated with a delimeter :. I tried

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.