package Stirng类;
/**
* String 常见的相关方法摘要
* @author Administrator
*
*/
public class DemoStringMethod {
public static void main(String[] args) {
String s = "hello world";
//charAt(int index) 返回指定索引处的char值
char c =s.charAt(6);
System.out.println(c);//w //compareTo(String anotherString);按字典顺序比较两个字符串
//compareToIgnoreCase(String str);忽略大小写比较
String s1 = "hello guigu";
int result = s.compareTo(s1);
System.out.println(result);//16 assic差值
int result1 = s1.compareTo(s);
System.out.println(result1);//-16 //concat(String str)将指定的字符串连接到此字符串的结尾
System.out.println(s.concat(s1));//hello worldhello guigu
System.out.println(s1.concat(s));//hello guiguhello world //endsWith(String suffix)-----测试此字符串是否以指定的后缀结束
//startsWith(String prefix)----测试此字符串是否以指定的前缀开始
System.out.println(s.endsWith("rld"));//true
System.out.println(s.startsWith("hel"));//true //使用指定的字符集将此String编码为byte序列,并将结果存储到一个新的byte数组中
byte [] arr = s.getBytes();
System.out.println(arr);
// for(byte qq:arr){
// System.out.println((char)qq);
// }
for(int i = 0;i<arr.length;i++){
System.out.println((char)arr[i]);
} //indexOf(int ch)//返回指定字符在此字符串中第一次出现处的索引
System.out.println(s.indexOf("w"));//
System.out.println(s.lastIndexOf("w"));//6 //replace(char oldChar,char newChar)
//返回一个新的字符串,它是通过用newChar 替换此字符串中出现的所有oldChar得到的
System.out.println(s.replace("l", "p"));//hello world------>heppo worpd //toLowerCase() toUpperCase() 转换大小写
System.out.println("AbcdEfG".toLowerCase());
System.out.println("AbcdEfG".toUpperCase()); //trim() 返回字符串的副本,忽略前后空格
System.out.println(" S D F a".trim()); String str1 = "hello";
String str2 = "hello"; String str3 = new String("hello");
String str4 = new String("hello"); System.out.println(str1==str2);//true
System.out.println(str1==str3);//false
System.out.println(str3==str4);//false System.out.println(str1.equals(str2));//true
System.out.println(str1.equals(str3));//true
System.out.println(str3.equals(str4));//true }
}

关于String的相关常见方法的更多相关文章

  1. String类的常见方法的使用案例

    String类的常见方法的使用案例 //使用指定的字符串替换当前字符串中指定的内容 //将helloworld中的o替换为a String s="HelloWorld"; Stri ...

  2. js String字符串对象常见方法总结

    String对象常用来保存文本形式的数据. 其转化方法有二种: String(s) new String(s) String对象方法有: charAt() charCodeAt() concat() ...

  3. String对象的常见方法

    String 对象方法 方法 描述 anchor() 创建 HTML 锚. big() 用大号字体显示字符串. blink() 显示闪动字符串. bold() 使用粗体显示字符串. charAt() ...

  4. 表格对象QTableWidget相关常见方法

    QWidget bool close (self)QRect geometry (self)hide (self)int height (self)setStatusTip (self, QStrin ...

  5. javascript常见方法汇总之一——数组字符串相关

    (转载至慕课网) 原文链接:https://www.imooc.com/article/46933 github地址:https://github.com/dorseysen/notes-about- ...

  6. JDK方法区、元空间区别 & String.intern相关面试题

    一.方法区.永久代.元空间 1.方法区.永久代 方法区也是各个线程共享的内存区域,它用于存储已经被虚拟机加载的类信息.常量.静态变量.即时编译器编译后的代码等数据.方法区域又被称为"永久代& ...

  7. 面向对象编程(四)继承,概念及super关键字,final关键字,Object类常见方法

    继承 概念: ①   继承背后的思想就是基于已存在的类来构建新类; ②   当从已存在类继承时,就重用了它的方法和属性,还可以添加新的方法和属性来定制新类以应对需求; ③   当从其它类导出的类叫作子 ...

  8. Java String的相关性质分析

    引言 String可以说是在Java开发中必不可缺的一种类,String容易忽略的细节也很多,对String的了解程度也反映了一个Java程序员的基本功.下面就由一个面试题来引出对String的剖析. ...

  9. Android View各种尺寸位置相关的方法探究

    Android View各种尺寸位置相关的方法探究 本来想做一个View间的碰撞检测之类的. 动手做了才发现不是想象的那么简单. 首先,写好了碰撞检测的工具类如下: package com.mengd ...

随机推荐

  1. Centos下安装jdk详解

    环境: 系统: [root@Wulaoer ~]# cat /proc/version Linux version 2.6.32-431.el6.x86_64 (mockbuild@c6b8.bsys ...

  2. jq中的css-Dom

    1,height() ,width() 此方法用来获取匹配元素的高和宽的值,如果括号内有值,则是修改匹配元素的值, 2.offset() 此方法的作用是获取元素在当前视窗的相对偏移,其中返回的对象包含 ...

  3. 测试redis+keepalived实现简单的主备切换【转载】

    转自: 测试redis+keepalived实现简单的主备切换 - Try My Best 尽力而为 - ITeye技术网站http://raising.iteye.com/blog/2311757 ...

  4. linux proxy

    ALL_PROXY=socks://192.168.2.1:3128/ HTTPS_PROXY=https://192.168.2.1:3128/HTTP_PROXY=http://192.168.2 ...

  5. 过滤字符串html标签方法

    过滤字符串html标签方法,如果输入的过滤标签为“*”,那么给字符串加上p标签 public static string noTagHtml(string str, string tagname) { ...

  6. PL/SQL DEVELOPER 导出表数据

    http://jingyan.baidu.com/album/fcb5aff78e6a48edab4a7146.html?picindex=4 1. 导出表数据 打开pl/sql客户端 在左侧 点击t ...

  7. web学习:Spring2.5+Hibernate3.3+Struts1.3整合小例子

    写android有段时间了,感觉思维越写越狭窄,考虑问题越来越局限了,看不到一个项目整体的设计和构架,觉得很有必要多多写一些大型的框架性的东西来提高自己的视野. 从接触java到现在一年多了,在我的印 ...

  8. Ubuntu 下开发 Android 环境变量设置

    -----------------------------------------------------ANDROID_SDK_HOME:/home/cmm/avds PATH:/home/cmm/ ...

  9. CentOS 7 安装 GlusterFS

    CentOS 7 GlusterFS 环境说明: 3台机器安装 GlusterFS 组成一个集群. 使用 docker volume plugin GlusterFS 服务器: 10.6.0.140 ...

  10. Struts2--Global Result全局结果集

    如果有很多action,有共同的result指向, 而且属于不同的包,那么可以继承上面的包, 然后写一个<global-results> 1. jsp显示文件: <ol> &l ...