Java学习----字符串函数
1.String
string类是最终类,不可以有子类
package com.demo.pkg1;
public class TestString {
public static void main(String[] agrs) {
// 构造字符串
String name = " hello world ";
String s1 = new String("aaa");
// 长度
int x = name.length();
// 字符位置
char c = name.charAt(3);
// 子串
String s = name.substring(5,8);
// 去掉空格
String ss = name.trim();
System.out.println(x);
System.out.println(c);
System.out.println(s);
System.out.println(ss);
}
}
15 e lo hello world
2.StringBuffer(可变)
public class TestString {
public static void main(String[] agrs) {
StringBuffer s = new StringBuffer("hello");
s.append(" world"); // string类型没有append
System.out.println(s);
System.out.println(s.toString()); // 转成string
}
}
hello world
3.StringBuilder
StringBuilder线程不安全,StringBuffer线程安全。单线程使用StringBuilder,可以更快一点。
Java学习----字符串函数的更多相关文章
- JAVA中字符串函数subString的用法小结
本篇文章主要是对JAVA中字符串函数subString的用法进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助 String str; str=str.substring(int begi ...
- java截取字符串函数
substring public String substring(int beginIndex)返回一个新的字符串,它是此字符串的一个子字符串.该子字符串始于指定索引处的字符,一直到此字符串末尾. ...
- Python学习-字符串函数操作3
字符串函数操作 isprintable():判断一个字符串中所有字符是否都是可打印字符的. 与isspace()函数很相似 如果字符串中的所有字符都是可打印的字符或字符串为空返回 True,否则返回 ...
- Python学习-字符串函数操作2
字符串函数操作 find( sub, start=None, end=None):从左到右开始查找目标子序列,找到了结束查找返回下标值,没找到返回 -1 sub:需要查找的字符串 start=None ...
- Java学习笔记-函数
Java也有着函数的概念,不过在OOP中,函数用作方法称呼 函数的定义 函数就是定义在类中的具有特定功能的一段独立小程序 函数也称为方法 函数的格式 修饰符返回值类型函数名(参数类型形式参数1,参数类 ...
- java学习之函数
讲完了语句结构还有运算符.变量,下面我们来了解下函数. 那么什么是函数,函数的定义是怎样的呢? 函数的定义: 函数是指在类当中定义的一段有特殊功能的代码段,同时函数在类中也被成为方法. class F ...
- Java\学习——字符串
import java.util.Scanner; public class cys1 { /** * @param args */ public static void main(String[] ...
- Python学习-字符串函数操作1
字符串的函数操作 capitalize():可以将字符串首字母变为大写 返回值:首字符大写后的新字符串 str = "liu" print(str.capitalize()); / ...
- Java学习----集合函数
1.List----有序的collection(序列) 与数组的不同:数据类型可以相同可以不同,数组的长度是预先定义好的,集合的长度也是预先定义好的,但是长度会随着元素的增加而增加 ArrayList ...
随机推荐
- Android TextView : “Do not concatenate text displayed with setText”
参考:http://stackoverflow.com/questions/33164886/android-textview-do-not-concatenate-text-displayed-wi ...
- 深入理解 Spring 事务原理
本文由码农网 – 吴极心原创,转载请看清文末的转载要求,欢迎参与我们的付费投稿计划! 一.事务的基本原理 Spring事务的本质其实就是数据库对事务的支持,没有数据库的事务支持,spring是无法提供 ...
- 【SQL】MySQL内置函数中的字符串函数和日期时间函数
字符串函数 --拼接字符串组成新的字符串 Select concat(‘A’,’B’); --返回字符串长度 Select length(“CAT”) --返回子字符串在字符串中首次出现的位置,没有返 ...
- Oracle 的 VKTM 进程 - virtual keeper of time
在Oracle Database 11g中,VKTM是一个新增的后台进程.这个进程的含义是: VKTM (virtual keeper of time) is responsible for prov ...
- PAT 1069. The Black Hole of Numbers (20)
For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in ...
- jquery mobile图片自适应屏幕
jquery mobile中如果不给img标签指定宽度的话,无法达到自适应屏幕的效果,特此备注:width:100%;
- 关于编译Lambda时报告返回的为void的错误
这个错误的信息是这样的: a lambda that has been specified to have a void return type cannot return a value 报告错误的 ...
- MFC ListControl使用方法
在原来博客中有:MF CListControl 简单功能使用 推荐文章:MFC类CtrlList用法 今天又又一次来介绍点新东西:双击击listcontrol 做出响应.当然你能够做的还有非常多,比 ...
- 如何在客户端配置ODBC来访问远程DB2 for Windows服务器
如何在客户端配置ODBC来访问远程DB2 for Windows服务器 马根峰 (广东联合电子服 ...
- [Angular 2] Component relative paths
Oingial aritial --> Link Take away: import { Component, OnInit } from '@angular/core'; @Component ...