添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
public class Test {
    public static void main(String[] args) {
        String str1 = "abc";
        String str2 = "abc";
        if(str1==str2)
            System.out.println(true);
        else{
            System.out.println(false);
        String str3=new String("abc");
        String str4=new String("abc");
        if(str3==str4)
            System.out.println(true);
        else{
            System.out.println(false);
        if(str3.equals(str4))//equals判断2个字符串是否相等只判断他们的值是否相等
            System.out.println(true);
false

1.可以看出str1和str2他们指向的同一个对象所以返回一个true

2.str3和str4是两个不同的对象返回值为false
3.判断2个字符串是否相等用equals()方法比较简单

本关任务:使用 new 创建两个字符串(获取键盘输入的两个字符串,中间用空格分隔),并分别通过 equals 和 == 判断字符串是否相等。 相关知识:为了完成本关任务,你需要掌握: 1.什么是字符串 2.字符串变量的声明 3.创建字符串的三种方式 4.equals 和 == 什么是字符串 我们已经知道,数字、字母、汉字、符号等等都是字符,如 9、A、a、国、& 等。 那么,什么是字符串呢? j 是一个字符,a、v、a 也是字符,现在我将这些字符连接起来,java 就是一个由 4 example1: String a="abc";String b="abc", 那么a==b将返回true。因为在java字符串的值是不可改变的,相同的字符串在内存中只会存 一份,所以a和b指向的是同一个对象; example2:String a=new String("abc"); String b=new String("abc");..
这个是参加上海某家数据咨询公司的Java笔试题,胡乱的写写,大神勿喷,菜鸟一枚。 题目:给你两个字符串,每个字符串的组成都是a-z,'*','.'这些符号,而*的功能是将其前面的字符删除,'.'可以替代任何一个字符,写一个算法判断两个字符串是否相等。     isMatch("a*","")=true;     isMatch("a.","ab")=true;     isMat
private static boolean isEquals(String... args) { for (int i = 0; i < args.length-1; i++) { if (i+1 == args.length){ break; if (!args[i].equals