How to store “ ” (whitespace) in an `int` array in Java
I have an int
array int a1;
At some point in my code, if the conditions meet, I want to replace the value of a[i]
to whitespace. For example, if my output is:
1 2 3 4 5 6
I want to make it:
1 2 4 5 6
How can I do that?
Edit: An integer array that contains a mixture of integers and spaces is a solution I came up with but it doesn’t seem to work. All I want is a way to get the output I’ve shown, and the purpose is to make my output more appealing. I’m making a memory game and I want to show a blank space when the guess is right so the user can see his progress.
java arrays
|
show 7 more comments
I have an int
array int a1;
At some point in my code, if the conditions meet, I want to replace the value of a[i]
to whitespace. For example, if my output is:
1 2 3 4 5 6
I want to make it:
1 2 4 5 6
How can I do that?
Edit: An integer array that contains a mixture of integers and spaces is a solution I came up with but it doesn’t seem to work. All I want is a way to get the output I’ve shown, and the purpose is to make my output more appealing. I’m making a memory game and I want to show a blank space when the guess is right so the user can see his progress.
java arrays
8
you can't. a space is not a valid int.
– Stultuske
Nov 20 '18 at 8:39
3
You can't do that with anint
array. If you use anInteger
array you can replace the value with anull
. When you print the array, you can choose what to display instead of thenull
value.
– Eran
Nov 20 '18 at 8:40
1
Take char array instead.
– Pooja Aggarwal
Nov 20 '18 at 8:41
3
This sounds like an XY problem (xyproblem.info). Can you explain why you want an integer array that contains a mixture of integers and spaces?
– ruakh
Nov 20 '18 at 8:44
1
@ΝίκοςΒαλτσιόγης if it's just for showing purposes, use String or char.
– Stultuske
Nov 20 '18 at 9:13
|
show 7 more comments
I have an int
array int a1;
At some point in my code, if the conditions meet, I want to replace the value of a[i]
to whitespace. For example, if my output is:
1 2 3 4 5 6
I want to make it:
1 2 4 5 6
How can I do that?
Edit: An integer array that contains a mixture of integers and spaces is a solution I came up with but it doesn’t seem to work. All I want is a way to get the output I’ve shown, and the purpose is to make my output more appealing. I’m making a memory game and I want to show a blank space when the guess is right so the user can see his progress.
java arrays
I have an int
array int a1;
At some point in my code, if the conditions meet, I want to replace the value of a[i]
to whitespace. For example, if my output is:
1 2 3 4 5 6
I want to make it:
1 2 4 5 6
How can I do that?
Edit: An integer array that contains a mixture of integers and spaces is a solution I came up with but it doesn’t seem to work. All I want is a way to get the output I’ve shown, and the purpose is to make my output more appealing. I’m making a memory game and I want to show a blank space when the guess is right so the user can see his progress.
java arrays
java arrays
edited Nov 20 '18 at 11:36
Ole V.V.
26.9k62751
26.9k62751
asked Nov 20 '18 at 8:38
Wal Choice
164
164
8
you can't. a space is not a valid int.
– Stultuske
Nov 20 '18 at 8:39
3
You can't do that with anint
array. If you use anInteger
array you can replace the value with anull
. When you print the array, you can choose what to display instead of thenull
value.
– Eran
Nov 20 '18 at 8:40
1
Take char array instead.
– Pooja Aggarwal
Nov 20 '18 at 8:41
3
This sounds like an XY problem (xyproblem.info). Can you explain why you want an integer array that contains a mixture of integers and spaces?
– ruakh
Nov 20 '18 at 8:44
1
@ΝίκοςΒαλτσιόγης if it's just for showing purposes, use String or char.
– Stultuske
Nov 20 '18 at 9:13
|
show 7 more comments
8
you can't. a space is not a valid int.
– Stultuske
Nov 20 '18 at 8:39
3
You can't do that with anint
array. If you use anInteger
array you can replace the value with anull
. When you print the array, you can choose what to display instead of thenull
value.
– Eran
Nov 20 '18 at 8:40
1
Take char array instead.
– Pooja Aggarwal
Nov 20 '18 at 8:41
3
This sounds like an XY problem (xyproblem.info). Can you explain why you want an integer array that contains a mixture of integers and spaces?
– ruakh
Nov 20 '18 at 8:44
1
@ΝίκοςΒαλτσιόγης if it's just for showing purposes, use String or char.
– Stultuske
Nov 20 '18 at 9:13
8
8
you can't. a space is not a valid int.
– Stultuske
Nov 20 '18 at 8:39
you can't. a space is not a valid int.
– Stultuske
Nov 20 '18 at 8:39
3
3
You can't do that with an
int
array. If you use an Integer
array you can replace the value with a null
. When you print the array, you can choose what to display instead of the null
value.– Eran
Nov 20 '18 at 8:40
You can't do that with an
int
array. If you use an Integer
array you can replace the value with a null
. When you print the array, you can choose what to display instead of the null
value.– Eran
Nov 20 '18 at 8:40
1
1
Take char array instead.
– Pooja Aggarwal
Nov 20 '18 at 8:41
Take char array instead.
– Pooja Aggarwal
Nov 20 '18 at 8:41
3
3
This sounds like an XY problem (xyproblem.info). Can you explain why you want an integer array that contains a mixture of integers and spaces?
– ruakh
Nov 20 '18 at 8:44
This sounds like an XY problem (xyproblem.info). Can you explain why you want an integer array that contains a mixture of integers and spaces?
– ruakh
Nov 20 '18 at 8:44
1
1
@ΝίκοςΒαλτσιόγης if it's just for showing purposes, use String or char.
– Stultuske
Nov 20 '18 at 9:13
@ΝίκοςΒαλτσιόγης if it's just for showing purposes, use String or char.
– Stultuske
Nov 20 '18 at 9:13
|
show 7 more comments
3 Answers
3
active
oldest
votes
Short answer: You can't store a space(a char) as an Integer, if is that what you're tryint to do.
I would change int to the Integer type so you can add null values to the array and if you find a null value I would print a white space instead.
However, you could get the numerical representation of such char, but in this case It changes the data type.
ehm ... you can store a char as an int. the problem is that storing ' ' to an int, and print it, prints a numerical value representing that char, not a space.
– Stultuske
Nov 20 '18 at 9:15
I've edited the post for a more complete unswer...
– Enrique de Miguel
Nov 20 '18 at 9:55
Thank you all for your answers,this however is what i was looking for and it solved my problem.Thank you.
– Wal Choice
Nov 21 '18 at 22:52
add a comment |
Edit
For your memory game I suggest a model class to hold the number and an indication whether it has been guessed. Something along these lines:
public class GameElement {
final int number;
boolean guessed = false;
public GameElement(int number) {
this.number = number;
}
public void setGuessed() {
guessed = true;
}
@Override
public String toString() {
if (guessed) {
return " ";
} else {
return String.valueOf(number);
}
}
}
You will probably want to put the item to be guessed into the class too so you have everything in one place (or I misunderstood something).
Even nicer, rather than relying on a toString
method, decide the presentation completely outside your model class. For this purpose, add getters getNumber
and isGuessed
so the presentation can access the data and decide how to present it to the user.
Original answer
As has been said in the comments, this is not possible.
You may choose a special int
value to mean “space” and remember to print it as a space each time. It’s fragile since a fellow programmer may forget to print the space and just print the int
value.
The gold-plated solution (hoping that you don’t need it): Design an abstract Element
class with two subclasses, IntElement
and SpaceElement
and create an array of Element
(you can probably find a better name). Have the IntElement
hold an int
and its toString
return a string representation of the int
. Have SpaceElement
contain no data and its toString
return a string consisting of a single space. Now you can fill your array with numbers and spaces as you like.
Thank you for your answer.
– Wal Choice
Nov 21 '18 at 22:59
add a comment |
In the comment you mention that you're making a memory game and the whitespace is there only to visualize "right guesses". With this in mind, you could keep the existing array as it is and introduce a parallel boolean guesses = new boolean[a1.length];
having the same size as the values array.
Then you'd update guesses[i] = true;
when there is a correct guess and print your array with something like
for (int i=0; i < a1.length; i++) {
System.out.print(guesses[i] ? " " : a1[i]);
}
seeing as it's only for visual representation, the values don't have to be numerical, it would be easier to use an array of String or char
– Stultuske
Nov 20 '18 at 9:19
Then you'd also lose the information about the original data (values to be guessed) in your memory game. This solution creates an abstraction layer between the game data and the guesses made.
– Mick Mnemonic
Nov 20 '18 at 9:19
how is that? you can compare non-int values just as easily as ints
– Stultuske
Nov 20 '18 at 9:21
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389069%2fhow-to-store-whitespace-in-an-int-array-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Short answer: You can't store a space(a char) as an Integer, if is that what you're tryint to do.
I would change int to the Integer type so you can add null values to the array and if you find a null value I would print a white space instead.
However, you could get the numerical representation of such char, but in this case It changes the data type.
ehm ... you can store a char as an int. the problem is that storing ' ' to an int, and print it, prints a numerical value representing that char, not a space.
– Stultuske
Nov 20 '18 at 9:15
I've edited the post for a more complete unswer...
– Enrique de Miguel
Nov 20 '18 at 9:55
Thank you all for your answers,this however is what i was looking for and it solved my problem.Thank you.
– Wal Choice
Nov 21 '18 at 22:52
add a comment |
Short answer: You can't store a space(a char) as an Integer, if is that what you're tryint to do.
I would change int to the Integer type so you can add null values to the array and if you find a null value I would print a white space instead.
However, you could get the numerical representation of such char, but in this case It changes the data type.
ehm ... you can store a char as an int. the problem is that storing ' ' to an int, and print it, prints a numerical value representing that char, not a space.
– Stultuske
Nov 20 '18 at 9:15
I've edited the post for a more complete unswer...
– Enrique de Miguel
Nov 20 '18 at 9:55
Thank you all for your answers,this however is what i was looking for and it solved my problem.Thank you.
– Wal Choice
Nov 21 '18 at 22:52
add a comment |
Short answer: You can't store a space(a char) as an Integer, if is that what you're tryint to do.
I would change int to the Integer type so you can add null values to the array and if you find a null value I would print a white space instead.
However, you could get the numerical representation of such char, but in this case It changes the data type.
Short answer: You can't store a space(a char) as an Integer, if is that what you're tryint to do.
I would change int to the Integer type so you can add null values to the array and if you find a null value I would print a white space instead.
However, you could get the numerical representation of such char, but in this case It changes the data type.
edited Nov 20 '18 at 10:22
answered Nov 20 '18 at 8:58
Enrique de Miguel
13319
13319
ehm ... you can store a char as an int. the problem is that storing ' ' to an int, and print it, prints a numerical value representing that char, not a space.
– Stultuske
Nov 20 '18 at 9:15
I've edited the post for a more complete unswer...
– Enrique de Miguel
Nov 20 '18 at 9:55
Thank you all for your answers,this however is what i was looking for and it solved my problem.Thank you.
– Wal Choice
Nov 21 '18 at 22:52
add a comment |
ehm ... you can store a char as an int. the problem is that storing ' ' to an int, and print it, prints a numerical value representing that char, not a space.
– Stultuske
Nov 20 '18 at 9:15
I've edited the post for a more complete unswer...
– Enrique de Miguel
Nov 20 '18 at 9:55
Thank you all for your answers,this however is what i was looking for and it solved my problem.Thank you.
– Wal Choice
Nov 21 '18 at 22:52
ehm ... you can store a char as an int. the problem is that storing ' ' to an int, and print it, prints a numerical value representing that char, not a space.
– Stultuske
Nov 20 '18 at 9:15
ehm ... you can store a char as an int. the problem is that storing ' ' to an int, and print it, prints a numerical value representing that char, not a space.
– Stultuske
Nov 20 '18 at 9:15
I've edited the post for a more complete unswer...
– Enrique de Miguel
Nov 20 '18 at 9:55
I've edited the post for a more complete unswer...
– Enrique de Miguel
Nov 20 '18 at 9:55
Thank you all for your answers,this however is what i was looking for and it solved my problem.Thank you.
– Wal Choice
Nov 21 '18 at 22:52
Thank you all for your answers,this however is what i was looking for and it solved my problem.Thank you.
– Wal Choice
Nov 21 '18 at 22:52
add a comment |
Edit
For your memory game I suggest a model class to hold the number and an indication whether it has been guessed. Something along these lines:
public class GameElement {
final int number;
boolean guessed = false;
public GameElement(int number) {
this.number = number;
}
public void setGuessed() {
guessed = true;
}
@Override
public String toString() {
if (guessed) {
return " ";
} else {
return String.valueOf(number);
}
}
}
You will probably want to put the item to be guessed into the class too so you have everything in one place (or I misunderstood something).
Even nicer, rather than relying on a toString
method, decide the presentation completely outside your model class. For this purpose, add getters getNumber
and isGuessed
so the presentation can access the data and decide how to present it to the user.
Original answer
As has been said in the comments, this is not possible.
You may choose a special int
value to mean “space” and remember to print it as a space each time. It’s fragile since a fellow programmer may forget to print the space and just print the int
value.
The gold-plated solution (hoping that you don’t need it): Design an abstract Element
class with two subclasses, IntElement
and SpaceElement
and create an array of Element
(you can probably find a better name). Have the IntElement
hold an int
and its toString
return a string representation of the int
. Have SpaceElement
contain no data and its toString
return a string consisting of a single space. Now you can fill your array with numbers and spaces as you like.
Thank you for your answer.
– Wal Choice
Nov 21 '18 at 22:59
add a comment |
Edit
For your memory game I suggest a model class to hold the number and an indication whether it has been guessed. Something along these lines:
public class GameElement {
final int number;
boolean guessed = false;
public GameElement(int number) {
this.number = number;
}
public void setGuessed() {
guessed = true;
}
@Override
public String toString() {
if (guessed) {
return " ";
} else {
return String.valueOf(number);
}
}
}
You will probably want to put the item to be guessed into the class too so you have everything in one place (or I misunderstood something).
Even nicer, rather than relying on a toString
method, decide the presentation completely outside your model class. For this purpose, add getters getNumber
and isGuessed
so the presentation can access the data and decide how to present it to the user.
Original answer
As has been said in the comments, this is not possible.
You may choose a special int
value to mean “space” and remember to print it as a space each time. It’s fragile since a fellow programmer may forget to print the space and just print the int
value.
The gold-plated solution (hoping that you don’t need it): Design an abstract Element
class with two subclasses, IntElement
and SpaceElement
and create an array of Element
(you can probably find a better name). Have the IntElement
hold an int
and its toString
return a string representation of the int
. Have SpaceElement
contain no data and its toString
return a string consisting of a single space. Now you can fill your array with numbers and spaces as you like.
Thank you for your answer.
– Wal Choice
Nov 21 '18 at 22:59
add a comment |
Edit
For your memory game I suggest a model class to hold the number and an indication whether it has been guessed. Something along these lines:
public class GameElement {
final int number;
boolean guessed = false;
public GameElement(int number) {
this.number = number;
}
public void setGuessed() {
guessed = true;
}
@Override
public String toString() {
if (guessed) {
return " ";
} else {
return String.valueOf(number);
}
}
}
You will probably want to put the item to be guessed into the class too so you have everything in one place (or I misunderstood something).
Even nicer, rather than relying on a toString
method, decide the presentation completely outside your model class. For this purpose, add getters getNumber
and isGuessed
so the presentation can access the data and decide how to present it to the user.
Original answer
As has been said in the comments, this is not possible.
You may choose a special int
value to mean “space” and remember to print it as a space each time. It’s fragile since a fellow programmer may forget to print the space and just print the int
value.
The gold-plated solution (hoping that you don’t need it): Design an abstract Element
class with two subclasses, IntElement
and SpaceElement
and create an array of Element
(you can probably find a better name). Have the IntElement
hold an int
and its toString
return a string representation of the int
. Have SpaceElement
contain no data and its toString
return a string consisting of a single space. Now you can fill your array with numbers and spaces as you like.
Edit
For your memory game I suggest a model class to hold the number and an indication whether it has been guessed. Something along these lines:
public class GameElement {
final int number;
boolean guessed = false;
public GameElement(int number) {
this.number = number;
}
public void setGuessed() {
guessed = true;
}
@Override
public String toString() {
if (guessed) {
return " ";
} else {
return String.valueOf(number);
}
}
}
You will probably want to put the item to be guessed into the class too so you have everything in one place (or I misunderstood something).
Even nicer, rather than relying on a toString
method, decide the presentation completely outside your model class. For this purpose, add getters getNumber
and isGuessed
so the presentation can access the data and decide how to present it to the user.
Original answer
As has been said in the comments, this is not possible.
You may choose a special int
value to mean “space” and remember to print it as a space each time. It’s fragile since a fellow programmer may forget to print the space and just print the int
value.
The gold-plated solution (hoping that you don’t need it): Design an abstract Element
class with two subclasses, IntElement
and SpaceElement
and create an array of Element
(you can probably find a better name). Have the IntElement
hold an int
and its toString
return a string representation of the int
. Have SpaceElement
contain no data and its toString
return a string consisting of a single space. Now you can fill your array with numbers and spaces as you like.
edited Nov 20 '18 at 11:50
answered Nov 20 '18 at 8:59
Ole V.V.
26.9k62751
26.9k62751
Thank you for your answer.
– Wal Choice
Nov 21 '18 at 22:59
add a comment |
Thank you for your answer.
– Wal Choice
Nov 21 '18 at 22:59
Thank you for your answer.
– Wal Choice
Nov 21 '18 at 22:59
Thank you for your answer.
– Wal Choice
Nov 21 '18 at 22:59
add a comment |
In the comment you mention that you're making a memory game and the whitespace is there only to visualize "right guesses". With this in mind, you could keep the existing array as it is and introduce a parallel boolean guesses = new boolean[a1.length];
having the same size as the values array.
Then you'd update guesses[i] = true;
when there is a correct guess and print your array with something like
for (int i=0; i < a1.length; i++) {
System.out.print(guesses[i] ? " " : a1[i]);
}
seeing as it's only for visual representation, the values don't have to be numerical, it would be easier to use an array of String or char
– Stultuske
Nov 20 '18 at 9:19
Then you'd also lose the information about the original data (values to be guessed) in your memory game. This solution creates an abstraction layer between the game data and the guesses made.
– Mick Mnemonic
Nov 20 '18 at 9:19
how is that? you can compare non-int values just as easily as ints
– Stultuske
Nov 20 '18 at 9:21
add a comment |
In the comment you mention that you're making a memory game and the whitespace is there only to visualize "right guesses". With this in mind, you could keep the existing array as it is and introduce a parallel boolean guesses = new boolean[a1.length];
having the same size as the values array.
Then you'd update guesses[i] = true;
when there is a correct guess and print your array with something like
for (int i=0; i < a1.length; i++) {
System.out.print(guesses[i] ? " " : a1[i]);
}
seeing as it's only for visual representation, the values don't have to be numerical, it would be easier to use an array of String or char
– Stultuske
Nov 20 '18 at 9:19
Then you'd also lose the information about the original data (values to be guessed) in your memory game. This solution creates an abstraction layer between the game data and the guesses made.
– Mick Mnemonic
Nov 20 '18 at 9:19
how is that? you can compare non-int values just as easily as ints
– Stultuske
Nov 20 '18 at 9:21
add a comment |
In the comment you mention that you're making a memory game and the whitespace is there only to visualize "right guesses". With this in mind, you could keep the existing array as it is and introduce a parallel boolean guesses = new boolean[a1.length];
having the same size as the values array.
Then you'd update guesses[i] = true;
when there is a correct guess and print your array with something like
for (int i=0; i < a1.length; i++) {
System.out.print(guesses[i] ? " " : a1[i]);
}
In the comment you mention that you're making a memory game and the whitespace is there only to visualize "right guesses". With this in mind, you could keep the existing array as it is and introduce a parallel boolean guesses = new boolean[a1.length];
having the same size as the values array.
Then you'd update guesses[i] = true;
when there is a correct guess and print your array with something like
for (int i=0; i < a1.length; i++) {
System.out.print(guesses[i] ? " " : a1[i]);
}
answered Nov 20 '18 at 9:17
Mick Mnemonic
6,45921923
6,45921923
seeing as it's only for visual representation, the values don't have to be numerical, it would be easier to use an array of String or char
– Stultuske
Nov 20 '18 at 9:19
Then you'd also lose the information about the original data (values to be guessed) in your memory game. This solution creates an abstraction layer between the game data and the guesses made.
– Mick Mnemonic
Nov 20 '18 at 9:19
how is that? you can compare non-int values just as easily as ints
– Stultuske
Nov 20 '18 at 9:21
add a comment |
seeing as it's only for visual representation, the values don't have to be numerical, it would be easier to use an array of String or char
– Stultuske
Nov 20 '18 at 9:19
Then you'd also lose the information about the original data (values to be guessed) in your memory game. This solution creates an abstraction layer between the game data and the guesses made.
– Mick Mnemonic
Nov 20 '18 at 9:19
how is that? you can compare non-int values just as easily as ints
– Stultuske
Nov 20 '18 at 9:21
seeing as it's only for visual representation, the values don't have to be numerical, it would be easier to use an array of String or char
– Stultuske
Nov 20 '18 at 9:19
seeing as it's only for visual representation, the values don't have to be numerical, it would be easier to use an array of String or char
– Stultuske
Nov 20 '18 at 9:19
Then you'd also lose the information about the original data (values to be guessed) in your memory game. This solution creates an abstraction layer between the game data and the guesses made.
– Mick Mnemonic
Nov 20 '18 at 9:19
Then you'd also lose the information about the original data (values to be guessed) in your memory game. This solution creates an abstraction layer between the game data and the guesses made.
– Mick Mnemonic
Nov 20 '18 at 9:19
how is that? you can compare non-int values just as easily as ints
– Stultuske
Nov 20 '18 at 9:21
how is that? you can compare non-int values just as easily as ints
– Stultuske
Nov 20 '18 at 9:21
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389069%2fhow-to-store-whitespace-in-an-int-array-in-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
8
you can't. a space is not a valid int.
– Stultuske
Nov 20 '18 at 8:39
3
You can't do that with an
int
array. If you use anInteger
array you can replace the value with anull
. When you print the array, you can choose what to display instead of thenull
value.– Eran
Nov 20 '18 at 8:40
1
Take char array instead.
– Pooja Aggarwal
Nov 20 '18 at 8:41
3
This sounds like an XY problem (xyproblem.info). Can you explain why you want an integer array that contains a mixture of integers and spaces?
– ruakh
Nov 20 '18 at 8:44
1
@ΝίκοςΒαλτσιόγης if it's just for showing purposes, use String or char.
– Stultuske
Nov 20 '18 at 9:13