String类的常用成员方法
方法 string 常用 成员
2023-09-14 09:12:03 时间
1、 构造方法:
String(byte[] byte,int offset,int length);这个在上面已经用到。
2、 equalsIgnoreCase:忽略大小写的比较,上例中如果您输入的是BYE,则不会退出,因为大小写不同,但是如果使用这个方法,则会退出。
3、 indexOf(int ch);返回字符ch在字符串中首次出现的位置
4、 substring(int benginIndex);
5、 substring(int beginIndex,int endIndex);
返回字符串的子字符串,4返回从benginindex位置开始到结束的子字符串,5返回beginindex和endindex-1之间的子字符串。
基本数据类型包装类的作用是:将基本的数据类型包装成对象。因为有些方法不可以直接处理基本数据类型,只能处理对象,例如vector的add方法,参数就只能是对象。这时就需要使用他们的包装类将他们包装成对象。
1 public class testInteger 2 { 3 public static void main(String[] args) 4 //main()的参数是string类型的数组,用来做为长,宽时,要转换成整型。 5 { 6 int w=new Integer(args[0]).intValue(); 7 int h=Integer.parseInt(args[1]); 8 //int h=Integer.valueOf(args[1]).intValue(); 9 //以上为三种将字符串转换成整形的方法。 10 for(int i=0;i<h;i++) 11 { 12 StringBuffer sb=new StringBuffer(); //使用stringbuffer,是因为它是可追加的。 13 for(int j=0;j<w;j++) 14 { 15 sb.append('*'); 16 } 17 System.out.println(sb.toString()); //在打印之前,要将stringbuffer转化为string类型。 18 } 19 } 20 }
相关文章
- linux 通过命令行终端去控制vnc终端【export DISPLAY使用方法】
- src引入js时添加时间戳参数方法
- canvas 1px 出现模糊解决方法及原理
- C#中string.Format()和ToString()格式化方法
- [Java基础]StringUtils.join()方法与String.join()方法的使用
- 【JS基础回顾】String对象及其常用属性以及方法
- C#基础知识系列一(goto、i++、三元运算符、ref和out、String和string、重载运算符)
- unity3d Light Probe Group图解超详细使用方法
- 【RF库测试】Encode String To Bytes&Decode Bytes To String& should be string&should be unicode string &should not be string
- 连接Mysql提示Can’t connect to local MySQL server through socket的解决方法
- js中setTimeout、setInterval、 clearInterval方法简介
- String方法取字符出现次数和字符最大相同
- 优化 recipe 达到快速启动 SAP Hybris Accelerator Storefront 的方法
- java——String方法的总结
- 【数据库已解决】Error【1146】:Table ‘xxx.xxx‘ doesn‘t exist问题原因及解决方法
- 4种语义分割数据集Cityscapes上SOTA方法总结
- String.format()方法详解
- Java中的Math函数常用方法总结
- Java中String类中compareTo( )方法
- python string 对齐文本的几个方法
- C# string.Format 和 String.Format 的区别
- C++删除string最后一个字符的几种方法
- Python全栈之路:string字符串常用方法
- 【编程语言】《C程序设计:现代方法》学习笔记
- 多种方法解决Failed to load class “org.slf4j.impl.StaticLoggerBinder“.的错误
- String转int的几种常用方法
- Java中main方法中的String args[]的用法
- Dart之字符串(String)的相关方法总结