can't print string and boolean value together in java

前端 未结 2 886
忘掉有多难
忘掉有多难 2021-01-29 12:43
public class Main
{
    public static void main(String[] args) {
        final String man1=\"All man are created equal:27\";
        final String man2=\"All man are crea         


        
2条回答
  •  借酒劲吻你
    2021-01-29 13:23

    The problem lies in this statement -

     System.out.print("All man are created equal:"+man1==man2); 
    

    here a new string (say s1) is generated with the concatenation of All man are created equal: and man1.
    Now you have 2 references of string s1 and man1.
    Later these two string references - s1 and man2 are compared.

    both references(s1 and man2) are different and you are getting false.

提交回复
热议问题