public class HelloWorld{
public static void main(String[] args){
final String SEX1 = "男";
final String SEX2 = "女";
System.out.println(SEX1);
System.out.println(SEX2);
}
}
final是多余的,删掉可以节省内存空间,减少资源浪费
package com.imooc;
import java.util.Arrays;
public class HelloWorld {
public static void main(String[] args){
String SEX1 = "男";
String SEX2 = "女";
System.out.println(SEX1+SEX2);
}
}
字符串本身就是常量,不可以被改变,所以不需要加final
public class HelloWorld{ public static void main(String[] args){ final String SEX1 = "男"; final String SEX2 = "女"; System.out.println(SEX1); System.out.println(SEX2); } }