Idea Code Analysis问题

Idea Code Analysis为什么建议用Java String的contains(Charquens s) 代替indexOf(String s)?是效率高还是因为阅读方便

图片描述

阅读 5.5k
1 个回答

应该是便于阅读,String的contains方法源码就是使用的indexOf

    /**
     * Returns true if and only if this string contains the specified
     * sequence of char values.
     *
     * @param s the sequence to search for
     * @return true if this string contains {@code s}, false otherwise
     * @since 1.5
     */
    public boolean contains(CharSequence s) {
        return indexOf(s.toString()) > -1;
    }
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题