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 ...
随机推荐
- PHP排序函数:sort()、rsort()、asort()、arsort()、ksort()、krsort()
sort()函数以升序对数组排序.rsort() 函数以降序对数组排序.asort() 函数对数组从低到高进行排序并保持索引关系.arsort() 函数对数组从高到低进行排序并保持索引关系.ksort ...
- 文本处理工具——sed进阶
一sed的搜索替代 (一)常见的和替代相关的选项 搜索替代,和vim的写法很像 s///:查找替换,支持使用其它分隔符,s@@@,s### p: 显示替换成功的行,就是打印. w /PATH/TO/S ...
- ansible_playbook语法中的循环语句归纳
种类一.标准循环添加多个用户 - name: add several users user: name={{ item }} state=present groups=wheel with_items ...
- c++ 获取文件图标,类型名称,属性 SHGetFileInfo
SHGetFileInfo是一个相当实用的Windows API函数. // [MoreWindows工作笔记4] 获取文件图标,类型名称,属性 SHGetFileInfo #include < ...
- nginx防止SQL注入规则
$request_uriThis variable is equal to the *original* request URI as received from the client includi ...
- idea 使用github
[Toc] #一.首先下载github for window 客户端,或者git客户端 这里只演示gitHub客户端,安装git客户端的话,git.exe很容易找得到. 附上网址:https://de ...
- jQuery 删除行(带跨行的表格)
jQuery 删除行(带跨行的表格) 实现效果,点击删除按钮后,在保证原来表格结构的基础上,移除当前行. 代码原理: 1.点击行后判断当前行的第一个<td>,是否包含rowspan属性,如 ...
- 2.Prometheus安装部署
环境准备 2台Linux操作系统(基于centos7) docker环境 配置 IP 角色 版本 192.168.229.139 prometheus-server 2.10 192.168.229. ...
- PAT甲级——1147 Heaps【30】
In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...
- 5.如何使用jmeter参数话
参数化:简单的来理解一下,我们录制了一个脚本,这个脚本中有登录操作,需要输入用户名和密码,假如系统不允许相同的用户名和密码同时登录,或者更好的模拟多个用户来登录系统.这个时候就需要对用户名和密码进行参 ...