I wish to accomplish:
String []beef = new String[3];
beef[0] = "Water";
beef[1] = "Chicken";
beef[2] = "Paper";
String empo = Arrays.toString(beef);
if (empo.isEmpty()){
empo = "Nothing";
System.out.println(empo);
}else{
System.out.println(empo);
}
without having to create the string.
Something like:
String []beef = new String[3];
beef[0] = "Water";
beef[1] = "Chicken";
beef[2] = "Paper";
Arrays.toString(beef); //change beef to just a plain string
if(beef.isEmpty()||beef==""){
no = "Nothing";
System.out.println(beef);
How would one go about doing this?
Java is a strongly and statically typed language. That means you have to tell it what type a thing will be when you declare it (strong typing), and you can't ever change it's type after that (static typing).
You will just have to create a new String.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With