Object类

  1. 列表项

String类

  1. 常用方法

构造方法

  • public String()
  • public String(byte[] bytes)
  • public String(byte[]bytes,int offset,int length)
  • public String(char[] value)
  • public String(char[] value,int offset,int count)
  • public String(String original)

String类的判断功能

  • boolean equals(Object obj)
  • boolean equalsIgnoreCase(String str)
  • boolean contains(String str)
  • boolean startsWith(String str)
  • boolean endsWith(String str)
  • boolean isEmpty()

String类的获取功能

  • int length()
  • char charAt(int index)
  • int indexOf(int ch)
  • int indexOf(String str)
  • int indexOf(int ch,int fromIndex)
  • int indexOf(String str,int fromIndex)
  • String substring(int start)
  • String substring(int start,int end)

String类的转换功能

  • byte[] getBytes()
  • char[] toCharArray()
  • static String valueOf(char[] chs)
  • static String valueOf(int i)
  • String toLowerCase()
  • String toUpperCase()
  • String concat(String str)

替换功能

  • String replace(char old,char new)
  • String replace(String old,Stringnew)

去除字符串两空格

  • String trim()

按字典顺序比较两个字符串

  1. int compareTo(String str)
  2. int compareToIgnoreCase(String str)

2.课堂笔记

  • string.equal重写的Object的toString()方法

下面两句代码的区别:

    String str1="abc";
String str2=new String("abc");
str1会先在常量池中查找,如果有的话就返回abc在常量池中的地址,将地址给str1。如果没有,就直接在常量池中创建,并将地址给str1。
str2会现在heap中 新建一个空间,然后在常量池中查找abc,如果有的
话,传值给 新建的空间,并将空间所在地址给str2.

string相关训练

            String s1 = new String("hello");
String s2 = new String("hello");
System.out.println(s1==s2); //false
System.out.println(s1.equals(s2)); //true String s3 = new String("hello");
String s4 = "hello";
System.out.println(s3==s4); //false
System.out.println(s3.equals(s4)); //true String s5 = "hello";
String s6 = "hello";
System.out.println(s5==s6); //true
System.out.println(s5.equals(s6)); //true

特别注意事项:

String s3="hello"
changeString(s3);
System.out.println("StringDemo2.main()"+s3);//结果为hello
public static void changeString(String s){
s="123";
}
原因是s3是字符常量,将s3的地址值传给了s,而后改变的是s,跟s3无关。

Object&&String学习的更多相关文章

  1. Object C学习笔记24-关键字总结

    学习Object C也有段时间了,学习的过程中涉及到了很多Object C中的关键字,本文总结一下所涉及到的关键字以及基本语法. 1.  #import #import <> 从syste ...

  2. Object C学习笔记22-#define 用法

    上一篇讲到了typedef 关键字的使用,可以参考文章 Object C 学习笔记--typedef用法 .而在c中还有另外一个很重要的关键字#define. 一. #define 简介 在C中利用预 ...

  3. Object C学习笔记21-typedef用法

    在上一章的学习过程中遇到了一个关键字typedef,这个关键字是C语言中的关键字,因为Object C是C的扩展同样也是支持typedef的. 一. 基本作用 typedef是C中的关键字,它的主要作 ...

  4. Object C学习笔记18-SEL,@ selector,Class,@class

    本章是对上一章<<Object C学习笔记17-动态判断和选择器>>的一点补充,所以比较简单点. 一. SEL 类型 在上一篇介绍了几个方法,都只是介绍了其使用方式但是没有具体 ...

  5. Object C学习笔记17-动态判断和选择器

    当时学习Object C的时被人鄙视了一顿,说使用.NET的思想来学Object C就是狗屎:不过也挺感谢这位仁兄的,这让我学习的时候更加的谨慎.今天的学习笔记主要记录Object C中的动态类型相关 ...

  6. C# 泛型 Func<object, string, bool> filter

    Func<object, string, bool>是泛型,你可以先把他看成一个普通类型,比如stringpublic class Func{ } // 自定义个普通类. Func fil ...

  7. js常用API 数据类型 基本类型,基本包装类型,引用类型 Object String Array Boolean Number Date Math

    数据类型 变量.作用域及内存 基础类型(primitive value):Undefined.Null.Boolean.Number和String.这些类型在内存中分别占用固定大小的空间,他们的值保存 ...

  8. Object C学习笔记10-静态方法和静态属性

    在.NET中我们静态使用的关键字static有着举足轻重的作用,static 方法可以不用实例化类实例就可以直接调用,static 属性也是如此.在Object C中也存在static关键字,今天的学 ...

  9. Object C学习笔记8-字符串NSString之二

    5. 字符串是否包含 hasPrefix 判断字符串是否以某个字符串开头 hasSuffix 判断字符串是否以某个字符串结尾 NSString *str1=@"Object C学习正在进行中 ...

随机推荐

  1. NuGet打包推送批处理以及MSBuild(通用版)

    使用时注意每个批处理里面的依赖工具路径指向 源码:https://github.com/easonjim/NuGetRun bug提交:https://github.com/easonjim/NuGe ...

  2. bzoj1124[POI2008]枪战maf

    这代码快写死我了.....死人最多随便推推结论.死人最少,每个环可以单独考虑,每个环上挂着的每棵树也可以分别考虑.tarjan找出所有环,对环上每个点,求出选它和不选它时以它为根的树的最大独立集(就是 ...

  3. php Unable to find the wrapper "https"

    php -m | grep -i --color openssl php 没有openssl模块 cd /data/source/php-5.3.29/ext/openssl #php的解压包下面 y ...

  4. Linux 命令之 Navicat 连接 Linux 下的Mysql数据库

    2016年12月7日18:44:06 -====------------------------  GRANT ALL PRIVILEGES ON *.* TO 'itoffice'@'%' IDEN ...

  5. java语言:Linux与JVM的内存关系分

    在一些物理内存为8g的服务器上,主要运行一个Java服务,系统内存分配如下:Java服务的JVM堆大小设置为6g,一个监控进程占用大约 600m,Linux自身使用大约800m.从表面上,物理内存应该 ...

  6. 与number_format函数有关的一个bug?

    最近在做一个模仿excel功能的在线项目.其中有一个功能,数据列表中的数据,到了最后一列都要进行总计.这本来没什么难度.直接从数据库取出数据后,进行foreach相加就行 了.这是如此的简单,以至于用 ...

  7. POJ 1947Rebuilding Roads(树形DP + 01背包)

    题目链接 题意:给出一个树形结构,求P个节点的子树最少要去掉几条边 分析:DP[root][j] 表示 以第 root 个为根节点, 包含j 个节点需要去掉几条边.那么对于 root 这个根节点来说, ...

  8. tomcat密码的坑

    <role rolename="tomcat"/> <role rolename="role1"/> <user username ...

  9. c++ http请求

    平常我们要访问某个URL一般都是通过浏览器进行:提交一个URL请求后,浏览器将请求发向目标服务器或者代理服务器,目标服务器或者代理服务器返回我们所需要的数据,浏览器接收到这些数据后保存成文件并进行显示 ...

  10. 自然语言18.2_NLTK命名实体识别

    QQ:231469242 欢迎nltk爱好者交流 http://blog.csdn.net/u010718606/article/details/50148261 NLTK中对于很多自然语言处理应用有 ...