`
lovnet
  • 浏览: 6670948 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
文章分类
社区版块
存档分类
最新评论

Java基础学习笔记之六(1)__常用类String

 
阅读更多

String 类

Strings are constant; their values cannot be changedafter they are created.
String 代表不可变的字符序列。

备注:在内存中的位置

String str = "abc";

1.引用str放在栈中
2.字符串常量放在常量池(字符串常量池)中,第一次创建放入池中,第二次使用直接把引用指向池中已有的数据。
3.new String("xxx")创建的 数据放在堆中,每次new都会在堆中创建一块内存存放数据。

常用方法

1.public char charAt(int index);
Returns the char value at the specified index.
返回指定索引处的 char 值

2.public int length();
Returns the length of this string.
返回此字符串的长度。

3.public int indexof(String str);
Returns the index within this string of
the first occurrence of the specified substring.
返回第一次出现的指定子字符串在此字符串中的索引。

4.public int indexof(String str,int fromIndex);
Returns the index within this string of the first occurrence
of the specified substring, starting at the specified index.
从指定的索引处开始,返回第一次出现的指定子字符串在此字符串中的索引

5.public boolean equalsIgnoreCase(String another);
Compares this String to another String, ignoring case considerations.
将此 String 与另一个 String 进行比较,不考虑大小写。

6.public String replace(char oldChar,char newChar)
Returns a new string resulting from replacing all occurrences of oldChar
in this string with newChar
返回一个新的字符串,它是通过用 newChar 替换此字符串中出现的所有 oldChar 而生成的
----------------------------------------------------
7.public boolean startWith(String prefix);
Tests if this string starts with the specified prefix.
测试此字符串是否以指定的前缀开始。

8.public boolean endsWith(String suffix);
Tests if this string ends with the specified suffix.
测试此字符串是否以指定的后缀结束。

9.public String toUpperCase();
Converts all of the characters in this String to
upper case using the rules of the default locale.
使用默认语言环境的规则将此 String 中的所有字符都转换为大写。

10.public String toLowerCase();
Converts all of the characters in this String to
lower case using the rules of the default locale.
用默认语言环境的规则将此 String 中的所有字符都转换为小写。
----------------------------------------------------
11.public String substring(int beginIndex);
Returns a new string that is a substring of this string.
返回一个新的字符串,它是此字符串的一个子字符串。
(返回该字符串从beginIndex开始到结尾的子字符串)

12.public String trim();
Returns a copy of the string, with leading
and trailing whitespace omitted.

返回字符串的副本,忽略前导空白和尾部空白。

----------------------------------------------------

13.public static String valueOf(...);
Returns the string representation of the Object argument.
返回 Object 参数的字符串表示形式。

14.public String[] split(String regex);
Splits this string around matches of the given regular expression.

根据给定的正则表达式的匹配来拆分此字符串。

参考文章:1.官方API http://docs.oracle.com/javase/6/docs/api/

分享到:
评论

相关推荐

    Java开发详解.zip

    000000_【课程介绍 —— 写在前面的话】_Java学习概述笔记.pdf 010101_【第1章:JAVA概述及开发环境搭建】_JAVA发展概述笔记.pdf 010102_【第1章:JAVA概述及开发环境搭建】_Java开发环境搭建笔记.pdf 010201_【第2...

    java学习笔记 初学者必读

    7.12.3. 五个最常用的集合类之间的区别和联系 7-33 7.12.4. 比较 7-35 7.13. 反射 7-37 8. 七•异常 8-37 8.1. 异常的基本概念 8-37 8.2. 捕获异常 8-38 8.3. 处理异常 8-38 8.4. 捕捉多个异常 8-38 8.5. finally ...

    cyc学习笔记.pdf

    2021秋招学习笔记总结,包含Java基础、Java并发、数据库、redis等常用后端技术等内容。数据类型 注:包装类型中一般设有缓冲池,比如Integer、String。 1、Integer缓存池范围-128~127都是同一个地址,在缓存池范围...

    java基础笔记

    java初学者的学习笔记,很详细。 目录 0 第一节 7月15日 2 一、 IT行业相关介绍 2 二、C、C++和Java语言的比较 2 三、 JDK基础介绍 2 四、 面向对象与面向过程的比较 2 五、 Java相关介绍 2 六、 Path和Classpath...

    java学习笔记

    匿名对象4.Random类5.ArrayList集合5.String类6.static关键字7.Arrays数组工具类8.Math数学工具类继承与多态1.继承2.抽象类3.接口4.多态5.final关键字6.权限修饰符7.内部类常用API第二部分1.Date类2.Calender类3.Sys

    Java学习笔记-个人整理的

    {1}Java基础}{17}{chapter.1} {1.1}基本语法}{17}{section.1.1} {1.2}数字表达方式}{17}{section.1.2} {1.3}补码}{19}{section.1.3} {1.3.1}总结}{23}{subsection.1.3.1} {1.4}数据类型}{23}{section.1.4} {...

    net学习笔记及其他代码应用

    声明方法的存在而不去实现它的类被叫做抽象类(abstract class),它用于要创建一个体现某些基本行为的类,并为该类声明方法,但不能在该类中实现该类的情况。不能创建abstract 类的实例。然而可以创建一个变量,其...

    观看韩顺平Java的 所做的笔记 到互斥锁 其中里面有我很多心得 老手可以用来复习 新手可以用学习 也可以当做参考 来做笔记

    包装类 String 类 字符串的特性 String 类的常见方法 StringBuffer 类 Math 类 Arrays 类 System 类 日期类包括1代2代3代 集合 集合的框架体系 Collection 接口和常用方法 Collection 接口实现类的特点 List 接口和...

    Flex新手教程_入门级学习笔记

    2.ActionScript3.0常用类 6 2.1内容现实类 6 2.2 String 6 2.3 Array类 8 2.4 XML和E4X 9 2.5 事件处理 Event 12 2.6异常和错误处理 13 3.Flex组件 15 3.1布局设计 15 3.3 MXML Module模块应用 16 3.4 表单 16 3.5 ...

    c#学习笔记.txt

    c#学习笔记(1) 51099在线学习网发布 文章来源:网络收集 发布时间:2006-05-25 字体: [大 中 小] 51099在线学习网 http://www.51099.com 1, 结构(struct) 与 类(class) [attributes] [modifiers] struct ...

    2009达内SQL学习笔记

    六、WHERE子句,选择、过滤 其后只能跟逻辑语句,返回值只有ture或false 如: select last_name,salary from s_emp where salary=1000;--找出工资1000的人 WHERE子句操作符: 1、逻辑比较运算符 = 等于 != ...

    Week02学习源码(配合博文笔记使用)

    java第二周学习源码,源码每行加注释。面向对象,继承多态,接口....api文档使用,集合 1.static关键字、继承 2.封装以及抽象类 3.内部类(了解) 4.常用类库 5.常用类库(Date Calender SimpleDateFormat) 6...

    攻克java大数类

    这篇博客作为我学习大数类的笔记。(我会持续更新的) BigInteger操作大整数 BigDecimal指定小数的保留位数 首先,long的范围是:-2^63 ~ 2^63-1 超过这个范围,就是用大数类,最好用string字符串类型进行接收。 ...

    Spring_IoC入门笔记.md

    在当前类需要用到其他类的对象时,由spring为我们提供,我们只需在配置文件中说明 依赖关系的维护:就称之为依赖注入 依赖注入: 注入方式:有三种 第一种:使用构造函数提供(创建对象时,必须提供数据,否则...

    asp.net知识库

    VS2005 ASP.NET本地化学习笔记&感受 在自定义Server Control中捆绑JS文件 Step by Step 深度解析Asp.Net2.0中的Callback机制 使用 Web 标准生成 ASP.NET 2.0 Web 站点 ASP.NET 2.0基于SQLSERVER 2005的aspnetdb.mdf...

    CLionProjects:学习阶段

    string :是编程语言中的字符串,字符串是一个特殊的对象,属于引用类型在的Java,C#中,字符串类对象创建后,字符串一旦初始化就不能更改,因为串类中所有字符串都是常量,数据是无法更改,由于字符串对象的不可...

Global site tag (gtag.js) - Google Analytics