PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 20, 2022

[FIXED] How do I check if my int array is empty, with the standard value being 0?

 July 20, 2022     arrays, integer, java, null, zero     No comments   

Issue

So I have come across an issue I do not seem to be able to fix. So lets say I have an int array and want to check whether the array still has space to add a certain element (from 0-∞) or has no space left, which would mean I would need to create a new array.

The issue is that when my int array has a space to store ten values, all of the spaces are filled with 0, so my program thinks that this array is full. And I can not exclude 0 either because the element which I want to add could be 0 aswell.

Any advice?


Solution

You are probably using an int[]? The primitive type int can not be null. A very simple solution would be to use the wrapper class Integer.

Integer[] intArray = {null, 0, 10};


Answered By - magicmn
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing