String的static方法
//String concat(String str) 拼接字符串
String concat_str0 = "abc";
String concat_str1 = "bcd";
String concat = concat_str0.concat(concat_str1);
System.out.println("拼接字符串concat:"+concat);//"abc"+"bcd"
System.out.println("------------------------------");
//boolean contains(CharSequence s) 判断一个字符串中是否包含某一个小串
String contains_str0 = "abcdefg";
String contains_str1 = "cde";
boolean contains = contains_str0.contains(contains_str1);
System.out.println("判断一个字符串中是否包含某一个小串contains:"+contains);
System.out.println("------------------------------");
//boolean startsWith(String prefix) 判断个字符串是否以另一个字符串开头
String startsWith_str0 = "abcdefg";
String startsWith_str1 = "ab";
boolean startsWith = startsWith_str0.startsWith(startsWith_str1);
System.out.println("判断个字符串是否以另一个字符串开头startsWith:"+startsWith);
System.out.println("------------------------------");
//boolean endsWith(String suffix) 判断个字符串是否以另一个字符串结尾的呢
//boolean equalsIgnoreCase(String anotherString) 判断 和另一个字符串的内容是否相同(不区分大小写的比较);
String equalsIgnoreCase_str0 = "abcdefg";
String equalsIgnoreCase_str1 = "Abcdefg";
boolean equalsIgnoreCase = equalsIgnoreCase_str0.equalsIgnoreCase(equalsIgnoreCase_str1);
System.out.println(" 判断 和另一个字符串的内容是否相同(不区分大小写的比较)equalsIgnoreCase:"+equalsIgnoreCase);
System.out.println("------------------------------");
//byte[] getBytes()把一个字符变成一个字节数组
String getBytes_str0 = "abc";
byte[] bytes = getBytes_str0.getBytes();
System.out.print("[");
for(int i = 0; i < bytes.length; ++i)
{
System.out.print(bytes[i]+" ");
}
System.out.println("]");
System.out.println("------------------------------");
//int indexOf(int ch) 在字符串中查找 某个字符第一次出现的索引。
String indexOf_first_ch0 = "abcdef";
int indexOf_first_ch = indexOf_first_ch0.indexOf('d');
System.out.println("在字符串中查找 某个字符第一次出现的索引indexOf:"+indexOf_first_ch);
System.out.println("------------------------------");
//int indexOf(int ch, int fromIndex) 从某个位置开始来算, 某个字符第一次出现的索引
String indexOf_first_from_ch0 = "abcdef";
int indexOf_first_from_ch = indexOf_first_from_ch0.indexOf('d', 4);
System.out.println("从某个位置开始来算, 某个字符第一次出现的索引indexOf:"+indexOf_first_from_ch);
System.out.println("------------------------------");
//int indexOf(String str) 在字符串中查找 某个小字符串第一次出现的索引。
String indexOf_first_str0 = "abcdefg";
int indexOf_first_str = indexOf_first_str0.indexOf("ef");
System.out.println("在字符串中查找 某个小字符串第一次出现的索引indexOf:"+indexOf_first_str);
System.out.println("------------------------------");
//int indexOf(int ch, int fromIndex) 从某个位置开始来算, 某个字符串第一次出现的索引
String indexOf_first_from_str0 = "abcdef";
int indexOf_first_from_str = indexOf_first_from_str0.indexOf('d', 4);
System.out.println("从某个位置开始来算, 某个字符串第一次出现的索引indexOf:"+indexOf_first_from_str);
System.out.println("------------------------------");
//int lastIndexOf(int ch) 字符串中查找(倒着查找) 某个小字符串第一次出现的索引。
String lastIndexOf_str0 = "abcdefg";
int lastIndexOf = lastIndexOf_str0.lastIndexOf('d');
System.out.println(" 字符串中查找(倒着查找) 某个小字符串第一次出现的索引lastIndexOf:"+lastIndexOf);
System.out.println("------------------------------");
//String replaceAll(String regex, String replacement) 在一个字符串中, 用一个新的小串,把所有的老小串 替换掉,
String replaceAll_str0 = "abfgcdeffghijfgk";
String replaceAll = replaceAll_str0.replace("fg", "oo");
System.out.println("在一个字符串中,用一个新的小串,把所有的老小串 替换掉replaceAll:"+ replaceAll);
System.out.println("------------------------------");
//String replaceFirst(String regex, String replacement) 在一个字符串中, 用一个新的小串,第一个出现的老小串 替换掉,
String replaceFirst_str0 = "abcdfgegfghijk";
String replaceFirst = replaceFirst_str0.replaceFirst("fg","oo");
System.out.println("在一个字符串中, 用一个新的小串,第一个出现的老小串 替换掉replaceFirst:"+ replaceFirst);
System.out.println("------------------------------");
//String[] split(String regex) 切割字符串
String split_str0 = "ab,cd,ef,gh";
String[] split = split_str0.split(",");
System.out.print("切割字符串split:"+"[ ");
for(int i = 0; i < split.length; ++i){
System.out.print(split[i]+" ");
}
System.out.println(" ]");
System.out.println("------------------------------");
//String substring(int beginIndex) 截取字符串
String substring_str0 = "abcdefg";
String substring = substring_str0.substring(2);
System.out.println("截取字符串substring:"+substring);
System.out.println("------------------------------");
//String substring(int beginIndex, int endIndex) 截取字符串从指定位置
String substring_from_str0 = "abcdefg";
String substring_from = substring_from_str0.substring(2,5);
System.out.println("截取字符串指定位置substring:"+substring_from);
System.out.println("------------------------------");
//char[] toCharArray() 把自已字符串转换为一个字符数组
String toCharArray_str0 = "abcdefg";
char[] toCharArray_chars = toCharArray_str0.toCharArray();
System.out.print("把自已字符串转换为一个字符数组toCharArray:"+"[ ");
for(int i = 0; i < toCharArray_chars.length; ++i){
System.out.print(toCharArray_chars[i]+" ");
}
System.out.println("]");
System.out.println("------------------------------");
//String toUpperCase() 把字符串转大写
//String toLowerCase() 把字符串转小写
String str0 = "AbbcDDef";
String toUpperCase = str0.toUpperCase();
String toLowerCase = str0.toLowerCase();
System.out.println("把字符串转大写toUpperCase:"+toUpperCase);
System.out.println("------------------------------");
System.out.println("把字符串转小写toLowerCase:"+toLowerCase);
System.out.println("------------------------------");
//String trim() 把字符两端的空格去除掉
String trim_str0 = " a b c d ";
String trim = trim_str0.trim();
System.out.println("把字符两端的空格去除掉trim:"+trim);
System.out.println("------------------------------");
//static String valueOf(char[] data) 把任意的东西转换为字符串
char []valueOf_chars = {'a','b'};
String valueOf = String.valueOf(valueOf_chars);
System.out.println("把任意的东西转换为字符串valueOf:"+valueOf);
System.out.println("------------------------------");
String的static方法的更多相关文章
- Java中String类的方法及说明
String : 字符串类型 一. String sc_sub = new String(c,3,2); // String sb_copy = new String(sb) ...
- java static 方法使用笔记
有入参的static方法,可以正常使用 static的作用是申明:这是类的静态方法,什么时候都可以调用,可以传入入参,也可以不传. 上代码: 1.带静态方法的类: public class MakeP ...
- spring框架中一个跟String的trim方法一样的方法
@Test public void testTrimWhitespace() throws Exception { assertEquals(null, StringUtils.trimWhitesp ...
- asp.net遍历页面中所有TextBox,并赋值为String.Empty的方法
本文介绍下,如何用.net遍历页面中的所有TextBox控件,并赋值为string.empty的方法,通过实例学习具体操作.有需要的朋友可以参考下. 一.遍历窗体控件 1,普通页面遍历TextBo ...
- java——多线程——单例模式的static方法和非static方法是否是线程安全的?
单例模式的static方法和非static方法是否是线程安全的? 答案是:单例模式的static方法和非static方法是否是线程安全的,与单例模式无关.也就说,如果static方法或者非static ...
- JVM学习03_new对象的内存图讲解,以及引出static方法(转)
目录 -=-讲解对象创建过程中,-=-堆内存和栈内存的情况 -=-构造函数对类对象的成员变量的初始化过程 -=-构造函数出栈 -=-类的方法在不访问类对象的成员变量时造成的内存资源浪费怎么解决? -= ...
- JAVA Static方法与单例模式的理解
近期用sonar測评代码质量的时候,发现一个问题,project中一些util类,曾经写的static方法都提示最好用单例的方式进行改正. 为此,我细致想了想,发现还是非常有道理的.这里谈谈我个人对s ...
- synchronized 修饰在 static方法和非static方法的区别
Java中synchronized用在静态方法和非静态方法上面的区别 在Java中,synchronized是用来表示同步的,我们可以synchronized来修饰一个方法.也可以synchroniz ...
- synchronized修饰static方法与非static方法的区别
1. 当synchronized修饰一个static方法时,多线程下,获取的是类锁(即Class本身,注意:不是实例),作用范围是整个静态方法,作用的对象是这个类的所有对象. 2. 当synchron ...
随机推荐
- 59th python下graphviz安装 砖
原文 摘录 感谢分享: https://www.cnblogs.com/liusx0303/p/9155305.html 参考链接:https://blog.csdn.net/u01325041 ...
- java基础学习笔记三(多态)
多态? 多态是同一个行为具有多个不同表现形式或形态的能力. 存在的必要条件 继承 重写 父类引用指向子类对象 比如: Parent p = new Child(); 当使用多态方式调用方法时,首先检查 ...
- springDataRedis 依赖
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit ...
- jdbc blob插入及查询操作
首先建一张表 create table picture( picId ) primary key not null, picName ) not null, picfile image null ) ...
- paper 134:结构张量structure tensor(二)
根据结构张量能区分图像的平坦区域.边缘区域与角点区域. 此算法也算是计算机科学最重要的32个算法之一了.链接的文章中此算法名称为Strukturtensor算法,不过我搜索了一下,Strukturte ...
- flutter环境搭建及跑起来demo(多图慎入)
话不多说,直接上 [1]环境搭建 从git上面clone下来 git clone -b beta https://github.com/flutter/flutter.git 由于国内网络的问题,我就 ...
- ARM 是什么
ARM Advanced RISC Machines. RISC 就是reduced instruction set computer 精简指令集计算机DSP digtal signal Proces ...
- python正常时间和unix时间戳相互转换的方法
python正常时间和unix时间戳相互转换的方法 本文实例讲述了python正常时间和unix时间戳相互转换的方法.分享给大家供大家参考.具体分析如下: 这段代码可以用来转换常规时间格式为unix时 ...
- Rust <10>:宏导出、导入
源 crate 中使用 #[macro_export] 属性标记的宏,调用者可在导入此 crate 时添加 #[macro_use] 属性使用. 没有 #[macro_export] 的宏,外部不可见 ...
- POI教程
很多时候,一个软件应用程序需要生成Microsoft Excel文件格式的报告.有时,一个应用程序甚至希望将Excel文件作为输入数据.例如,一个公司开发的应用程序将财务部门需要所有输出生成自己的Ex ...