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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:37:47+00:00 2026-06-01T07:37:47+00:00

I have read up on it a bit and I understand that in java

  • 0

I have read up on it a bit and I understand that in java you can’t change the original value of given parameters and expect those to persist after the method is over. But I’d really like to know a good way to do this. Could someone give me some pointers on what I could do to make this method work? Thanks.

/**
* This will set values in the given array to be "" (or empty strings) if they are null values
*
* @param checkNull
*/
public static void setNullValuesBlank(String... checkNull) {
  for (int i = 0; i < checkNull.length; i++) {
    String check = checkNull[i];
    if (check == null) {
      check = "";
    }
  }
}

EDIT

So I have to set it to the array as several people mentioned, and it works great if I construct the array in the first place, but if I don’t then it doesn’t work.

Here’s the fixed method:

/**
  * This will set values in the given array to be "" (or empty strings) if they are null values
  *
  * @param checkNull
  */
public static void setNullValuesBlank(String... checkNull) {
  for (int i = 0; i < checkNull.length; i++) {
    if (checkNull[i] == null) {
      checkNull[i] = "";
    }
  }
}

Here’s a call where it works:

String s = null;
String a = null;
String[] arry = new String[]{s, a};
for (int i = 0; i < arry.length; i++) {
  System.out.println(i + ": " + arry[i]);
}
setNullValuesBlank(arry);
for (int i = 0; i < arry.length; i++) {
  System.out.println(i + ": " + arry[i]);
}

Here’s a call where it doesn’t work, but I want it to:

String q = null;
String x = null;
System.out.println("q: " + q);
System.out.println("x: " + x);
setNullValuesBlank(q, x);
System.out.println("q: " + q);
System.out.println("x: " + x);

Output of that:

q: null
x: null
q: null
x: null
  • 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-01T07:37:48+00:00Added an answer on June 1, 2026 at 7:37 am

    You need to assign to the array:

    if (checkNull[i] == null) {
      checkNull[i] = "";
    }
    

    Assigning to the check will not change the array.

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

Sidebar

Related Questions

I have read a lot that LISP can redefine syntax on the fly, presumably
I have read (or perhaps heard from a colleague) that in .NET, TransactionScope can
PHP's documentation on this function is a bit sparse and I have read that
I want to come up with a language syntax. I have read a bit
I've read around quite a bit but haven't found a definitive answer. I have
I have read that using database keys in a URL is a bad thing
I have read on Stack Overflow some people that have converting to C#2.0 to
I have read the documentation on this and I think I understand. An AutoResetEvent
I program in Java and have been trying to understand exactly what operator overloading
Maybe I am asking the wrong question completely. I have read quite a bit

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.