java 基础功能

摘要:
)③字符串charAt;//获取字符publicclassTest4{publicstatic void main{Strings=“abcdefg”;System.out.println;}}输出结果:(索引从0开始,前面有两个空格,也是两个字符。
public class Test4{
	public static void main(String[] args) {
		String  s="abcdefg";
		System.out.println(s.length());
	   }
    }

 ①上面代码:str.length();// 获取整个字符串的长度 

输出结果:java 基础功能第1张(abcdefg的位数是七位。)

②str.trim();// 去掉字符串两边的空格

public class Test4{
	public static void main(String[] args) {
		String  s="  abcdefg  ";(两边都有空格)
		System.out.println(s.trim());
	   }
    }

输出结果:java 基础功能第2张  (两边的空格没有了。)

③str.charAt(int i);// 获取某个索引值上的字符

public class Test4{
	public static void main(String[] args) {
		String  s="  abcdefg  ";
		System.out.println(s.charAt(6));
	   }
    }

输出结果:java 基础功能第3张   (索引从0开始,前面有两个空格,也算是两个字符。)

④str.contains(CharSequence s);// 是否包含某个字符串

public class Test4{
	public static void main(String[] args) {
		String  s = "abcdefg"; 
        System.out.println(s.contains("ab"));
        System.out.println(s.contains("abf"));		
	   }
    }

输出:java 基础功能第4张(字符串abcdefg中有ab字符串为true,但是没有abf为false。)

⑤ str.startsWith(String s);字符串开始的字符串
⑥str.endsWith(String s);字符串结束的字符串

public class Test4{
	public static void main(String[] args) {
		String  s = "abcdefg"; 
        System.out.println(s.startsWith("ab"));
        System.out.println(s.endsWith("g"));		

	   }
    }

输出:java 基础功能第5张(abcdefg字符串中是以ab开头以fg结束所以为true)

⑦ replace(char o, char n);替换字符
⑧ replace(CharSequence o, CharSequence n);

public class Test4{
	public static void main(String[] args) {
		String  s = "abcdefg"; 
        System.out.println(s.replace("a","b"));
	   }
    }

输出:java 基础功能第6张

⑨split(String s);拆分字符串放到数组里

public class Test4{
	public static void main(String[] args) {
		String  s = "a,b,c,d,e,f,g"; 
		String[]_s=s.split(",");
			for( int i = 0; i<_s.length; i++){
					System.out.println(_s[i]);
			}		
	   }
    }

输出:java 基础功能第7张

⑩ toUpperCase();转换为大写

public class Test4{
	public static void main(String[] args) {
		String  s = "abcdefg"; 
        System.out.println(s.toUpperCase());
 
	   }
    }

输出:java 基础功能第8张

11、toLowerCase();转换为小写
12 、valueOf(any args);讲任意参数或者对象转换为string格式输出

public class Test4{
	public static void main(String[] args) {
		String  s = "abcdefg"; 
        System.out.println(String.valueOf(1234));
 
	   }
    }

输出:java 基础功能第9张

 13、 str.indexOf(String s);//取这个字符串第一次出现的索引位置
 14、 str.lastIndexOf(String s);//取这个字符串最后一次出现的索引位置

public class Test4{
	public static void main(String[] args) {
		String  s = "abcbdfeffgabcbdfeffg"; 
        System.out.println(s.indexOf("b"));
		System.out.println(s.lastIndexOf("f"));
 
	   }
    }

输出:java 基础功能第10张(字符串abcbdfeffgabcbdfeffg第一次出现b的索引是1最后一次出现f的索引是18)

 15 、 str.substring(int i);//取索引值为这个整数参数后面的字符串
 16、 str.substring(int a, int b);//取a和b之间的字符串(不包括b)

public class Test4{
	public static void main(String[] args) {
		String  s = "abcbdfeffgabcbdfeffg"; 
        System.out.println(s.substring(3));
		System.out.println(s.substring(3,5));
 
	   }
    }

输出:java 基础功能第11张

 

免责声明:文章转载自《java 基础功能》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Python爬虫学习==&amp;gt;第五章:爬虫常用库的安装python 面向对象下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

解决Maven无法下载fastdfs-client-java依赖,Dependency 'org.csource:fastdfs-client-java:1.27-SNAPSHOT' not found.

然后,您成功地将fastdfs客户端java打包到本地Maven仓库,更新项目Maven,pom.xml文件将不会找不到fastdfs客户机java依赖项。...

oracle 在sql中显示blob的字符串

最近在用oracle的过程中用到了对blob字段模糊查询的问题,对oracle来说,我并不是高手,找了很多的资料终于能够查出来了。以上只是自己做了个简单的处理,相信肯定有更好的方法,希望大家帮忙,但是感觉dbms_lob函数下的方法真的很好用。...

Java 读取ANSI文件中文乱码问题解决方式[转]

Filefile=newFile(路径);InputStreamin=newjava.io.FileInputStream(文件);BufferedReader读取器=新的BufferedReader(读取);FileInputStreamin=newFileInputStream(文件);byte[]b=新字节[3];内容如下(b);...

layui table 打印表格

例如,layui的表单打印方法是将表单的数据重新组合成新页面,但它只能打印当前页面的内容。仅仅说实话是不够的。我整个上午都找到了一些,并说他们自己换了,但他们并不满意。这没用。我只能打印当前页面的内容。我的想法是编写一个函数,传递显示的列和要打印的数据,然后直接打印。不要胡说八道。直接转到代码。...

linux下ifconfig, DNS以及route配置

Linux基本网络配置命令1.ifconfig查看网络接口信息。普通用户使用的ifconfig的完整路径:/sbin/ifconfigifconfig网络接口名称:显示指定接口的详细信息。...

SpringBoot源码深度解析

Spring开源框架解决了企业开发的复杂性,简化了AOP的开发,IOCSpring配置越来越多,不易管理==如何自动配置Springboot,核心原则!Java领域最流行的技术!公司,如何演变结构!...