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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:13:18+00:00 2026-06-10T01:13:18+00:00

I have following String Array tmp = [null, null, null, Mars, Saturn, Mars] coming

  • 0

I have following String Array
tmp = [null, null, null, Mars, Saturn, Mars] coming after doing the operation –
allSig[d3].split(" "); where allSig is an array of Strings. The null value is empty value in the array. Now I want to remove the null. For this I am using

tmp[indexNumber] != null is not working and giving true ; taking null as the value. Even if i am using “null” as a string is not working.

How to remove this.

public static String[] removeElements(String[] allElements) {
    String[] _localAllElements = new String[allElements.length];

    for (int i = 0; i < allElements.length; i++)
        if (allElements[i] != null)
            _localAllElements[i] = allElements[i];

    return _localAllElements;
}
  • 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-10T01:13:20+00:00Added an answer on June 10, 2026 at 1:13 am
    public static String[] clean(final String[] v) {
      int r, w;
      final int n = r = w = v.length;
      while (r > 0) {
        final String s = v[--r];
        if (!s.equals("null")) {
          v[--w] = s;
        }
      }
      return Arrays.copyOfRange(v, w, n);
    }
    

    or

    public static String[] clean(final String[] v) {
      int r, w, n = r = w = v.length;
      while (r > 0) {
        final String s = v[--r];
        if (!s.equals("null")) {
          v[--w] = s;
        }
      }
      final String[] c = new String[n -= w];
      System.arraycopy(v, w, c, 0, n);
      return c;
    }
    

    Works fine…

    public static void main(final String[] argv) {
      final String[] source = new String[] { "Mars", "null", "Saturn", "null", "Mars" };
      assert Arrays.equals(clean(source), new String[] { "Mars", "Saturn", "Mars" });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following string fromat: session=11;reserID=1000001 How to get string array of number?
I have the following as two ways to declare a two dimensional String array.
I have the following code to populate an array of strings, but every time
I have the following issue related to iterating over an associative array of strings
I have the following JavaScript data structure. a[] is an array with text strings
I have the following string called MasterVersion : 1.1-SNAPSHOT I need to split it
I have the following String: (X,Y,Z),(A,B,C),(R,S,T) I want to split this into a multi-dimensional
I have following array string[] words = { cherry, apple, blueberry, banana, mango, orange,
I have the following string pattern: 1:2,2:3 . This is like array in one
I have the following string: (1-$500.00)(2-$20.00) I want to turn it into an 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.