answersLogoWhite

0


Best Answer

A character array, by nature, is a primitive-type data array. It can't contain a null value. You cannot cast a char as a null.

char[] charArray = {'1','2','s',null}; //this doesn't compile.

However, if you have an array of Character objects, then it's possible.

Character[] charArray = {'1','2','s',null}; //this DOES compile

A proposed algorithm is to initialize a test boolean as false, then use a for loop to iterate through the array. Set the flag to true (and break the loop) based upon whether one of the objects you run into is null. What you do from there is up to what the rest of your code says.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can i check a null at the end of an character array in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is java string?

array of character data type which is terminated by null character


A character array terminated with the null character is most correctly called what?

zero-terminated string


Why we don't use NULL character in array?

Because it is not a character, it is a pointer. Anyway, the following is perfectly legal: char str [4] = { 'A', 'B', 'C', (char)NULL};


The character automatically included at the end of an array of characters is?

Sometimes it's called null character and it's '\0';


Why is c string defined as an array?

Every programming language treats strings as arrays. A C string is defined as being a null-terminated array of characters. A C string that does not have a null-terminator is just an array of character values, but without a null-terminator the onus is upon the programmer to keep track of the array's length.


How can one prove that an array is not null but emptyin java?

You can copy paste the below code into a file named Test.java and execute it. inside the main block you can see the if condition. check if the list is not null and then use the size parameter of the array list to check if it is empty. import java.util.ArrayList; public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ArrayList lst = new ArrayList(); if(lst != null && lst.size() == 0){ System.out.println("Array list is empty"); } } }


What is array of string?

An array of strings is usually implemented as an array of character pointers. Each pointer refers to a a null-terminated character array, and can be treated just as if it were a two-dimensional array where the length of each "row" is not fixed length (the null terminator marks the end of each row). The array of character pointers must be allocated in contiguous memory (as must all one-dimensional arrays), however the character arrays they point to need not be allocated contiguously with each other (only the individual one-dimensional character arrays must be contiguous).


What is mean by Extra key inserted at the end of Array?

It means the array has a sentinel to mark the end of the array. Any elements that follow the sentinel element are deemed invalid. Sentinels are usually denoted with a special value that is not used by any of the elements that precede it. Null-terminated strings are an example, where the NULL character (ASCII code 0) marks the end of a character array.


What String of what?

An array of strings is usually implemented as an array of character pointers. Each pointer refers to a a null-terminated character array, and can be treated just as if it were a two-dimensional array where the length of each "row" is not fixed length (the null terminator marks the end of each row). The array of character pointers must be allocated in contiguous memory (as must all one-dimensional arrays), however the character arrays they point to need not be allocated contiguously with each other (only the individual one-dimensional character arrays must be contiguous).


What symbol or character determines end of string?

In C programming language, a string is an array of characters which is always terminated by a NULL character: '\0'


What is the difference between array and string of array?

When we declare an array of characters it has to be terminated by the NULL , but termination by NULL in case of string is automatic.


How strings and characters are represented in an array?

An array of characters is an array of character codes (such as ASCII codes). A string is typically a null-terminated array of characters however some languages use the first array element to specify the string's length.