更改数组为字符串而无需创建一个字符串 [英] Change an array to a string without creating a string

查看:93
本文介绍了更改数组为字符串而无需创建一个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做到:

    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是强烈并的 的静态类型语言。这意味着你必须告诉它的事情会是什么类型的,当你把它声明(强类型),而且你永远不能改变它是(静态类型)后类型。

You can't.

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.

这篇关于更改数组为字符串而无需创建一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆