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. HDU 5889 (最短路+网络流)

    Barricade Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  2. 浅谈:html5和html的区别

    什么是html5呢? html5最先由WHATWG(Web 超文本应用技术工作组)命名的一种超文本标记语言,随后和W3C的xhtml2.0(标准)相结合,产生现在最新一代的超文本标记语言.可以简单点理 ...

  3. input text设置字体

    控件里设置: style="font-family:Arial" html里设置 <font face="Arial">

  4. iOS之tabbar图片去除渲染以及字体颜色统一配置

    转发:http://www.cnblogs.com/qianLL/p/5521228.html   方式一  代码实现 这种要写很多代码 ,每个控制器都要写   UIImage *image=[UII ...

  5. 风格一致的backItem在项目中怎样设置

    在相应的navigationController中重写- (void)pushViewController:(UIViewController *)viewController animated:(B ...

  6. 10、end关键字和Fibonacci series: 斐波纳契数列

    # Fibonacci series: 斐波纳契数列 # 两个元素的总和确定了下一个数 a, b = 0, 1 #复合赋值表达式,a,b同时赋值0和1 while b < 10: print(b ...

  7. Codeforces Round #368 (Div. 2)D. Persistent Bookcase DFS

    题目链接:http://codeforces.com/contest/707/my 看了这位大神的详细分析,一下子明白了.链接:http://blog.csdn.net/queuelovestack/ ...

  8. Eclipse 配置工程

    Eclipse改UTF-8 Window->Preferences->General->Workspace->Text file Encoding Eclipse配置tomca ...

  9. ecos资源探测器

    两种类型的资源探测器 xml文件资源探测器 目录资源探测器 系统内置的资源探测器(核心) 数据库定义目录资源探测器 -base_application_datable 关注dbschema servi ...

  10. iOS之UIColloctionView

    iOS--UICollectionView(滚动视图)入门 UICollectionView @interface UICollectionView : UIScrollView UICollecti ...