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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:04:11+00:00 2026-06-15T08:04:11+00:00

I have a string array that contains some information. Example: String [] testStringArray; testStringArray[0]=

  • 0

I have a string array that contains some information.

Example:

 String [] testStringArray;

 testStringArray[0]= Jim,35
                     Alex,45 
                     Mark,21

 testStringArray[1]= Ana,18
                    Megan,44

This is exactly how the information is. Now my problem is I want to make each element a seperate element in an array and I want to split it based on the \n character.

So I want

        newArray[0]=Jim,35
        newArray[1]=Alex,45
        newArray[2]=Mark,21
        newArray[3]=Ana,18

etc etc. I am aware of the split method but won’t this just split each array element into a completely new array instead of combining them?

If anyone could help, it would be appreciated. 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-06-15T08:04:13+00:00Added an answer on June 15, 2026 at 8:04 am

    Something like this:

        // Splits the given array of Strings on the given regex and returns
        // the result in a single array.
        public static String[] splitContent(String regex, String... input) {
            List<String> list = new ArrayList<>();
            for (String str : input) {
                for (String split : str.split(regex)) {
                    list.add(split);
                }
            }
            return list.toArray(new String[list.size()]);
        }
    

    you can call it this way:

        String[] testStringArray = ...;
        String[] newArray = splitContent("\n", testStringArray);
    

    Because of the use of varargs you can also call it like this:

        String[] newArray = splitContent("\n", str1, str2, str3, str4);
    

    where strX are String variables. You can use any amount you want. So either pass an array of Strings, or any amount of Strings you like.

    If you don’t need the old array anymore, you can also use it like this:

        String[] yourArray = ...;
        yourArray = splitContent("\n", yourArray);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code that will check the array contains the specific string and
I have one array that contains some settings that looks like basically like this:
I have string that look like Array that fetched from other webservice like this
friends. I have an array and it contains some string values. ex: array name=All_array
Say I have an $input array, that contains something like this : array 0
I have an array tab1 that contains some strings and another array that could
I have a global JavaScript array that contains some strings. I want to create
I have a string that contains some values I need to extract. Each of
I have a hashmap that contains multiple string arrays. I am trying to output
I have a variable that contains : Sometimes array of strings and sometimes array

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.