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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:48:56+00:00 2026-06-12T18:48:56+00:00

I have an array of String like so: array[0] = 1 4 array[1] =

  • 0

I have an array of String like so:

array[0] = "1 4"
array[1] = "2 0"
array[2] = "2 1"
array[3] = "4 2"

and would like to process the array and print out the second part of the array element
on the same line when the first part of the array element have duplicates, like this:

4
0 1
2

I’ve been trying ages to work this out but I keep getting more confused…

Processing is based on consecutive lines.

  • 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-12T18:48:57+00:00Added an answer on June 12, 2026 at 6:48 pm

    It looks like a straight-forward Java coding problem to me:

    String lastKey = null;
    for (String str : array) {
       String[] parts = str.split(" ");
       if (parts[0].equals(lastKey)) {
           System.out.print(" ");
       } else if (lastKey != null) {
           System.out.println();
       }
       System.out.print(parts[1]);
       lastKey = parts[0];
    }
    System.out.println();
    

    This assumes that your input file is ordered on the first field …

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

Sidebar

Related Questions

I have string like {param1=foo}{param2=bar}hello world! I need to extract array of tuples (paramName,
An array is defined of assumed elements like I have array like String[] strArray
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
So, I have a string array of some random saying and the like, but
How do i explode this string '||25||34||73||94||116||128' i need to have a array like
I have string that look like Array that fetched from other webservice like this
I have the following string that I would like to Huffman-encode and store efficiently
I have an array which is storing server addresses like so $servers = array(
I've got a class with many string arrays. I'd like to have one generic
I have defined an array like so : var myArray = {myNewArray: ['string1' ,

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.