Arrays must have a fixed length.

If your goal is to have a dynamically expansible list, consider a List instead. Everytime you add an item by add() method, it will grow dynamically whenever needed.

List<Character> chars = new ArrayList<>();
// ...

See also:

  • Java Tutorials > Trail: Collections > The List Interface
Answer from BalusC on Stack Overflow
๐ŸŒ
DaniWeb
daniweb.com โ€บ programming โ€บ software-development โ€บ threads โ€บ 275722 โ€บ check-if-char-array-is-empty
java - Check if char array is empty | DaniWeb
As jwenting noted, primitive arrays are never "empty" in Java; char elements default to '\u0000' (NUL), not null. So a single cell is empty if it holds your chosen sentinel, not by comparing two indexes.
Discussions

How to represent empty char in Java Character class - Stack Overflow
...and use new String(char[]) to ... is all java btw). you will observe all chars set to zero are simply not there and all duplicates are gone. long post, but just wanted to give you an example. so yes set char c = 0; or if for char array, set cArray[i]=0 for that specific duplicate character and you will have removed it. ... You can't. "" is the literal for a string, which contains no characters. It does not contain the "empty character" ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - How can I check if the char array has an empty cell so I can print 0 in it? - Stack Overflow
Change it to: if(position[i][j] == 0) Each char can be compared with an int. The default value is '\u0000' i.e. 0 for a char array element. And that's exactly what you meant by empty cell, I assume. More on stackoverflow.com
๐ŸŒ stackoverflow.com
April 25, 2017
What is the value of an empty cell in a char array (Java)? - Stack Overflow
Default values for primitives are 0, 0.0f, 0.0 (double), (char)0 and false (for boolean). Applies to arrays and single variables. ... In Java, char[] array = new char[4]; will set all the memory associated to that array to zero. More on stackoverflow.com
๐ŸŒ stackoverflow.com
April 11, 2014
How to represent empty char in Java Character class - Stack Overflow
...and use new String(char[]) to ... is all java btw). you will observe all chars set to zero are simply not there and all duplicates are gone. long post, but just wanted to give you an example. so yes set char c = 0; or if for char array, set cArray[i]=0 for that specific duplicate character and you will have removed it. ... Save this answer. ... Show activity on this post. You can't. "" is the literal for a string, which contains no characters. It does not contain the "empty character" ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 15, 2014
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ character-array-in-java
Character Array in Java - GeeksforGeeks
January 22, 2026 - A character array in Java is an array that stores multiple characters (char) in contiguous memory locations.
๐ŸŒ
Quora
quora.com โ€บ How-can-I-set-a-character-array-to-null-in-Java-Or-empty-it
How to set a character array to null in Java? Or empty it - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
๐ŸŒ
Delft Stack
delftstack.com โ€บ "delft stack" โ€บ "howto" โ€บ "java howtos" โ€บ "how to represent empty char in java"
How to Represent Empty Char in Java | Delft Stack
February 2, 2024 - While in Java, it is possible to have an empty char[] array, the concept of an empty char itself is not applicable.
Find elsewhere
๐ŸŒ
Mccue
javabook.mccue.dev โ€บ arrays โ€บ empty_array
Empty Array - Modern Java
If you use an array initializer that has no elements between the { and } you can create an empty array. char[] emptyCharArray = {}; An empty array is very similar to an empty String. It has a length of 0, it has no elements, and it is generally useful only as a placeholder value for when you ...
๐ŸŒ
Whaa
whaa.dev โ€บ how-to-create-a-char-array-in-java
How to create a char array in Java?
June 11, 2022 - char[] array = new char[3]; // [ , , ] <-- NULL characters System.out.println(java.util.Arrays.toString(array));
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ is it possible to declare a blank array with multiple spaces?
r/javahelp on Reddit: Is it possible to declare a blank array with multiple spaces?
July 13, 2020 -

I'm trying to write a method that involves taking an int and using that number to create an array of that size. However, the contents of the array are not known at initialization. Is there a way to declare an array with (for example) ten blank spaces?

I tried

int[] MyArray = new int[Num];
MyArray[Num] = Num; 

but that only creates an array with Num at the first index.

Thanks for any help, I really appreciate it :)

๐ŸŒ
Javatpoint
javatpoint.com โ€บ character-array-in-java
Character Array in Java - Javatpoint
Java program to find the percentage of uppercase, lowercase, digits and special characters in a string
Top answer
1 of 3
6

A Java String is not an array of characters (nor is it a single char, which is an integral primitive type). It is an Object type, and includes a length.

JLS-10.9. An Array of Characters is Not a String says (in part)

In the Java programming language, unlike C, an array of char is not a String, and neither a String nor an array of char is terminated by '\u0000' (the NUL character).

A String object is immutable, that is, its contents never change, while an array of char has mutable elements.

I mean in the end each character in the string will be stored as a BYTE, now how a empty string will be stored?

No, each character is 2 bytes. The Java Tutorials: Primitive Data Types says

The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

In the case of an empty String there aren't any characters; and an empty array has length 0.

2 of 3
4

String is certainly backed by a char[] (a field known as value), but that does not under any circumstance imply that a String is exactly equivalent to a char[]. They're two different objects.

Now, with that out of the way, let's reason about what we're expecting with a String of length zero. This is how we determine length:

/**
 * Returns the length of this string.
 * The length is equal to the number of <a href="Character.html#unicode">Unicode
 * code units</a> in the string.
 *
 * @return  the length of the sequence of characters represented by this
 *          object.
 */
public int length() {
    return value.length;
}

The big thing here to note is that if we're creating an empty string, the length of our backing array has to be zero. So, the way that an empty String is created is by providing an empty value array at instantiation.

๐ŸŒ
LinuxQuestions.org
linuxquestions.org โ€บ questions โ€บ programming-9 โ€บ empty-char-in-java-95407
empty char in java
September 22, 2003 - Hi everyone, I want to initialize an empty char in java, but I just found out that isn't as simple as I thought. I tried Code: char ch = ''; But that