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. Oracle sql语句创建表空间、数据库、用户及授权

    --创建表空间和数据库文件及默认表空间大小 create tablespace TableSpace_Test datafile 'E:\ORACLE\PRODUCT\10.2.0\ORADATA\O ...

  2. 分类算法-----KNN

    摘要: 所谓K最近邻,就是k个最近的邻居的意思,说的是每个样本都可以用她最接近的k个邻居来代表.kNN算法的核心思想是如果一个样本在特征空间中的k个最相似的样本中的大多数属于某一个类别,则该样本也属于 ...

  3. make -jN

    今天又一次尝试编译安卓,想测试一下编译的速度如何? 考虑机器是4核8线程,就用上了 make -j8,感觉上上速度是很快,刷屏就下来了,不过错误了,错误的提示大概是某个文件的规则没找到,想想了多线程并 ...

  4. CentOS 在同一窗口打开文件夹

    1.打开一个文件夹 2.编辑 - 首选项 - 行为,勾选“总是在浏览器窗口打开”,点击关闭.

  5. HDU 2087 剪花布条(KMP基础应用)

    KMP基础,注意输入 #include<cstdio> #include<cstring> #include<iostream> using namespace s ...

  6. POJ 2723 HDU 1816 Get Luffy Out

    二分答案 + 2-SAT验证 #include<cstdio> #include<cstring> #include<cmath> #include<stac ...

  7. USACO Section 1.2 Palindromic Squares 解题报告

    题目 题目描述 输入一个基数B,现在要从1到300之间找出一些符合要求的数字N.如果N的平方转换成B进制数之后是一个回文串,那么N就符合要求.我们将N转换成B进制数输出,然后再将N的平方转换成B进制数 ...

  8. HTML知识点

    1. 首页布局 // 顶部DIV#top{ position:absolute; top:; left:; width:100%; height:15%; overflow:hidden; margi ...

  9. ffmpeg ffplay ffprobe资料整理

    1. 官网地址:https://ffmpeg.org/ 官网文档地址:https://ffmpeg.org/documentation.html 官网下载地址:https://ffmpeg.org/d ...

  10. javascript第一篇----使用简介

    使用技巧 Javascript加入网页有两种方法:直接方式和引用方式. 直接方式 直接调用分为两种形式:代码块和代码行 代码行引用: <a href="javascript:alert ...