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. AutoIt3(AU3)开发的分辨率快速设置工具

    项目相关地址 源码:https://github.com/easonjim/Resolution_Settings bug提交:https://github.com/easonjim/Resoluti ...

  2. android下载简单工具类

    功能是实现下载文件,图片或MP3等,为了简单起见使用单线程,此代码为MarsAndroid教程的复制品,放在此处,留着参考. 首先是一个得到字节流随后保存到内存卡上的工具类: package com. ...

  3. poj2187 旋转卡(qia)壳(ke)

    题意:求凸包的直径 关于对踵点对.旋转卡壳算法的介绍可以参考这里: http://www.cnblogs.com/Booble/archive/2011/04/03/2004865.html http ...

  4. HDU 1002 A + B Problem II

    A + B Problem II   Time Limit: 1000MS      Memory Limit: 65536K Total Submissions: 16104    Accepted ...

  5. Jacobian矩阵和Hessian矩阵

    1.Jacobian矩阵 在矩阵论中,Jacobian矩阵是一阶偏导矩阵,其行列式称为Jacobian行列式.假设 函数 $f:R^n \to R^m$, 输入是向量 $x \in R^n$ ,输出为 ...

  6. 超强语感训练文章(Provided by Rocky teacher Prince)

    Content: Class1 My name is Prince Class2 Welcome to our hotel Class3 We’re not afraid of problems Cl ...

  7. Python 培训之正则表达式

    re 模块 re.math 从头匹配 re.search 结构: re.math(r'^c',a)   不符合返回None 原字符: . 任意字符 [ ] 或者 [A-Z,a-z,b] \d 数字 \ ...

  8. for 循环的关键字 break和continue

    for(int i=0;i<100;i++){ if(i==50){ continue:// 跳出当前循环,执行下面的循环,就是说,当i=50的时候,跳出循环,从i=51开始继续循环 //业务逻 ...

  9. ci查询数据库

    public function getUsers() { $this->load->database();//载入数据库 $users = $this->db->get(&qu ...

  10. easyui numberbox一些常用属性,方法

    1.value="1234567.89"//数字框中的值 2.precision:2//精度(小数点后两位) 3.groupSeparator:','//(组分隔符) 4.deci ...