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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:55:35+00:00 2026-06-10T23:55:35+00:00

I have a string that I want to split with a certain delimiter private

  • 0

I have a string that I want to split with a certain delimiter

private int [] mMaxValues;

    public void setMaximum(String maximum) {
       mMaxValues = splitByDelimiter(maximum, ":");
    }

But the splitByDelimiter method return a string array into an int array

public String[] splitByDelimiter(String list,String delimiter) {
    String[] items = list.split("\\" + delimiter);

    for (String s : items) {
        s.trim();
    }

    return items;
}

What is the best way to fix this problem? I’m guessing that iterating the string array and casting them to integers isn’t the best solution.

I could also create a new splitByDelimiter that returns an int array but I’m guessing there is a better solution than that..

Is this a situation where you could use generics (I don’t have a lot of experience with generics)?

Thx 🙂

  • 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-10T23:55:36+00:00Added an answer on June 10, 2026 at 11:55 pm

    You need to convert string array to int array explicitly. Use:

    public void setMaximum(String maximum) {
       Strin[] array = splitByDelimiter(maximum, ":");
       int i = 0;
       mMaxValues = new int[array.length];
       for (String value : array) {
           mMaxValues[i] = Integer.parseInt(value);
           i++;
       }
    }
    

    Also you need to handle few cases which may cause NullPointerException :

    1. maximum is null
    2. array is null
    3. NumberFormatException may be raised while parsing Integer.parseInt(value), handle it.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string s that I want to split up so each part
I have a string like 8/29/2011 11:16:12 AM . I want to split that
lets say I have a string that I want to split based on several
I have a string like: {A}{B}={C}{D}<{E}{F}<= What I want to do is split that
I have a string that represents a path to a directory. I want split
I have a string that's like this: 1|value|; I want to split that string
Possible Duplicate: Split string, convert ToList<int>() in one line… i have a string that
I have a String that I want to split based on punctuation marks and
I have a very long string that I want to split into 2 pieces.
I have a string which I want to split using a certain set of

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.