String[] str = {"a","b","c","d","e"}; 或String[] sql = new String[] {};

1、对String定义与赋值时使用:
String[] str = {"a","b","c","d","e"};
和String[] sql = new String[] {"a","b","c","d","e"};的区别是什么?
2、定义就是指String[] str;
赋值和初始化是指:str = {"a","b","c","d","e"};或str = ew String[] {"a","b","c","d","e"};?

谢谢!
最新回答
微浅笑°

2024-12-02 06:35:05

首先这两种方式都是创建了字符串数组。
但是第一种方式只创建了一个String[]数组对象str。
第二种方式创建了两个String[]数组对象sql和 new String[] {"a","b","c","d","e"},相当于我创建了 new String[] {"a","b","c","d","e"};这个对象,然后把这个对象的引用赋给sql对象。
其实我过得并不好

2024-12-02 09:01:08

前面一个创建了一个对象,后面一个创建了2个对象,前面一个先检查存在{"a","b","c","d","e"}不,存在就直接赋值,不存在就先创建再赋值,后面始终是先创建再赋值,从效率上来讲,前面那个更高
万花丛中一朵菊

2024-12-02 09:33:08

String[] str = {"a","b","c","d","e"}; 隐式调用string实例化

String[] sql = new String[] {}; 显示调用string实例化

效果一样的!!
大众电灯泡!

2024-12-02 06:28:21

1..两个没有什么区别..都是一样的..

2..是那样的..前面是定义..后面是赋值..
帅癌晚期

2024-12-02 07:48:43

方式一样,且创建的对象也是一样的。