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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:37:04+00:00 2026-05-27T07:37:04+00:00

string = #1x#2#3#4#5#6#; String array[] = string.split(#); for(int count=0;count<=6;count++){ // String temp = array[count];

  • 0
string = "#1x#2#3#4#5#6#";

    String array[] = string.split("#");
    for(int count=0;count<=6;count++){
        // String temp = array[count];
        String temp1 = array[count].substring(0,1).trim();//here temp1="1"
        //  String temp1 = "1"; //this is possible 
        log (Integer.parseInt( temp1));// i cant convert the array which is populated by split("delimiter") why ??
    }

Here’s the array:

array[]=("1","2","3","4","5","6"}

I can convert the the String array[] into integer when i am declaring this as normal String array but when i am using split and populating the String array here in this example .

I am ready to explain if you can’t understand too. Help me out in this?
The Error is

Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)

My question is Integer.parseInt(string_array_populated_by_split_method[count]) is throwing Exception

Here the return value is a string “1” i.e Integer.parseInt(“1”).. this “1” is generated by split() method

Thanks in Advance.

  • 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-27T07:37:04+00:00Added an answer on May 27, 2026 at 7:37 am

    You are doing a

    substring(0, 0)
    

    which is returning "", and "" cannot be converted to int. If you want to get the first character, you need to do:

    substring(0, 1)
    

    Then why you are trimming a single character, I don’t know…

    Edit

    Your new problem is:

    The fact that your String starts with a # means that the first value in your array will be a "", and this one is causing problem. What you can do is testing that the String length is superior that 0:

    for(String current : array){
        if(current.length() > 0) {  
            String temp1 = current.substring(0,1);
            log (Integer.parseInt( temp1));
        }
    } 
    

    Or you could also make sure that your String at the beginning isn’t starting with a #.

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

Sidebar

Related Questions

Trying to split this string 主楼怎么走 into separate characters (I need an array) using
In C# I need to split a string (a log4j log file) into array
I need to split my string input into an array at the commas. Is
PHP's explode function returns an array of strings split on some provided substring. It
Consider a string array shaped like this: string[] someName = new string[] { First,
for (int z = 0; z < alParmValues.Count; z++) { //string[] def; string[] asd
I build up an array of strings with string[] parts = string.spilt( ); And
I have a string array in C# and I intend to copy it in
I got a string array and values are as follows sNames[0] = Root |
I have a string array: string[] authors = new string[3]; authors[0] = Charles Dickens;

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.