/*
String(char[] value)传递字符数组 将字符数组转换为字符串 字符数组不查询编码表
*/
public static void fun1(){
char[] ch = {'a','b','c','d','e','f'};
String s= new String(ch);
String s1= new String(ch,1,2); System.out.println(s1);
} /*
String(char[] value,int offeset,int count);
offeset 代表数组开始的索引、count代表个数
将字节转换为字符串
*/
public static void fun2(){
byte[] bytes={97,98,99,100,101};
String str=new String(bytes);
System.out.println(str);
byte[] bytes1 = {97,98,99,100,101};
//调用构造方法 传递数组 传递两个int下x,y 代表截取 截取的位置 x代表下标开始的位置 y代表结束位置
String s = new String(bytes1,1,3);
System.out.println(s); } /*
int length(); 返回的是字符串的长度
*/
public static void fun3(){
String s="skjl";
int i=s.length();
System.out.println(i);
} /*
substring(int beginIndex,int endIndex)获取字符串的一部分 包含头 不包含尾 即截取字符串
substring(int beginIndex) 该索引后边全部截取
*/
public static void fun4(){
String s="helloword";
String s2=s.substring(2);
String s1=s.substring(1,4);
System.out.println(s1);
System.out.println(s2);
} /*
boolean startaWith(String preFix) 判断一个字符串是否以该字符开头
*/
public static void fun5(){
String s="helloworld";
boolean s1=s.startsWith("hello");
System.out.println(s1);
} /*
判断一个字符串的后缀 结尾 endWith("参数");
*/
public static void fun6(){
String s="helloworld";
boolean s1=s.endsWith("world");
System.out.println(s1);
}
/*
contains 判断一个字符是否有另一个字符
*/
public static void fun7(){
String s="helloworld";
boolean s1=s.contains("ll");
System.out.println(s1);
} /*
indexof(String str) 返回int 返回为查找字符的索引 返回-1没有找到 */
public static void fun8(){
String s="hello.java";
int s1=s.indexOf('j');
System.out.println(s1);
} /*
将字符串转字节数组 getBytes();以asill码方式输出
*/
public static void fun9(){
String s="今天天气真好!";
byte[] s1=s.getBytes();
for(int i=0;i<s1.length;i++){
System.out.println(s1[i]);
}
}
/*
将字符串转为字符数组
toCharArray()
原样输出 */ public static void fun10(){ String s="今天天气真好!"; char[] ch=s.toCharArray(); for(int i=0;i<ch.length;i++){ System.out.println(ch[i]); } } /* boolean equals(object obj);判断字符串里边完全相等 返回true s.equalslgnoreCase(object obj); 不区分大小写 的比较 */ public static void fun11(){ String s="hello"; String s1="hELLO"; System.out.println(s.equals(s1)); //false System.out.println(s.equalsIgnoreCase(s1)); //true  } /* 获取首字母方法 charAt(0) substring(0,1) 转成大写字母 toUpperCase() 获取剩余字符串 substring(1) toLowerCase() 转小写 */ public static void main(String[] args) { String s="heLLo"; String s2=s.substring(0,1); System.out.println("heLLo首字母为: "+s2); String s3=s2.toUpperCase(); System.out.println("转为大写字母后为: "+s3); String s4=s.substring(1).toLowerCase(); System.out.println("剩下的字母转换为小写后为: "+s4); System.out.println("最终输出的结果为: "+s3+""+s4); }

最新文章

  1. html5中新增非主体结构元素
  2. PeopleSoft Home Subdirectories
  3. stm32中断无电平触发的解决办法
  4. C#之发送邮件汇总
  5. SVN服务器详细权限控制
  6. java使用dom4j解析xml文件
  7. 杭电ACM2057--A + B Again
  8. 常见Oracle数据库问题总结及解决办法(一)
  9. 浙大pat 1054 题解
  10. 深入了解MyBatis返回值
  11. TCP长连接和短连接的区别
  12. sql 时间转换问题 from_unixtime() UNIX_TIMESTAMP()
  13. 我的.net并发系列文章及项目经验整理
  14. xml错误之cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element &#39;mvc:annotation-driven&#39;.
  15. flyway和liquibase的使用样例
  16. 安装Hive过程中报错:Unsupported major.minor version 52.0
  17. 开发宏功能:excel中从sheet批量插入
  18. webpack使用中遇到的问题
  19. WinDBG相关
  20. spring cloud学习(一) 服务注册

热门文章

  1. css进行网站布局
  2. Civil 3D 二次开发 创建Civil 3D 对象—— 01 —— 创建几何空间点
  3. Eclipse环境配置与快捷命令
  4. Kibana-4.6.6 marvel插件license过期重新注册
  5. Android Dialog 简单封装
  6. HBase 清空表数据
  7. JeeSite 部署到linux服务器
  8. 【宝塔linux】 导入mysql 大文件失败的问题
  9. Hdoj 1785.You Are All Excellent 题解
  10. 15 Zabbix Item类型之Zabbix trapper类型