public class StringDemo{
public static void main(String args[]){
char[] helloArray = { 'r', 'u', 'n', 'o', 'o', 'b'};
String helloString = new String(helloArray);
System.out.println( helloString );
}
}
public class StringDemo {
public static void main(String args[]) {
String site = "www.runoob.com";
int len = site.length();
System.out.println( "菜鸟教程网址长度 : " + len );
}
}
public class StringDemo {
public static void main(String args[]) {
String string1 = "菜鸟教程网址:";
System.out.println("1、" + string1 + "www.runoob.com");
}
}
System.out.printf("浮点型变量的值为 " +
"%f, 整型变量的值为 " +
" %d, 字符串变量的值为 " +
"is %s", floatVar, intVar, stringVar);
String fs;
fs = String.format("浮点型变量的值为 " +
"%f, 整型变量的值为 " +
" %d, 字符串变量的值为 " +
" %s", floatVar, intVar, stringVar);
public class Test {

    public static void main(String args[]) {
String s = "www.runoob.com";
char result = s.charAt(8);
System.out.println(result);
}
}
public class Test {

    public static void main(String args[]) {
String str1 = "Strings";
String str2 = "Strings";
String str3 = "Strings123"; int result = str1.compareTo( str2 );
System.out.println(result); result = str2.compareTo( str3 );
System.out.println(result); result = str3.compareTo( str1 );
System.out.println(result);
}
}

public class Test {

    public static void main(String args[]) {
String str1 = "STRINGS";
String str2 = "Strings";
String str3 = "Strings123"; int result = str1.compareToIgnoreCase( str2 );
System.out.println(result); result = str2.compareToIgnoreCase( str3 );
System.out.println(result); result = str3.compareToIgnoreCase( str1 );
System.out.println(result);
}
}

public class Test {
public static void main(String args[]) {
String s = "菜鸟教程:";
s = s.concat("www.runoob.com");
System.out.println(s);
}
}
public class Test {
public static void main(String args[]) {
String str1 = "String1";
String str2 = "String2";
StringBuffer str3 = new StringBuffer( "String1"); boolean result = str1.contentEquals( str3 );
System.out.println(result); result = str2.contentEquals( str3 );
System.out.println(result);
}
}

public class Test {
public static void main(String args[]) {
char[] Str1 = {'h', 'e', 'l', 'l', 'o', ' ', 'r', 'u', 'n', 'o', 'o', 'b'};
String Str2 = ""; Str2 = Str2.copyValueOf( Str1 );
System.out.println("返回结果:" + Str2); Str2 = Str2.copyValueOf( Str1, 2, 6 );
System.out.println("返回结果:" + Str2);
}
}
public class Test {
public static void main(String args[]) {
String Str = new String("菜鸟教程:www.runoob.com");
boolean retVal; retVal = Str.endsWith( "runoob" );
System.out.println("返回值 = " + retVal ); retVal = Str.endsWith( "com" );
System.out.println("返回值 = " + retVal );
}

public class Test {
public static void main(String args[]) {
String Str1 = new String("runoob");
String Str2 = Str1;
String Str3 = new String("runoob");
boolean retVal; retVal = Str1.equals( Str2 );
System.out.println("返回值 = " + retVal ); retVal = Str1.equals( Str3 );
System.out.println("返回值 = " + retVal );
}
}
public class Test {
public static void main(String args[]) {
String Str1 = new String("runoob");
String Str2 = Str1;
String Str3 = new String("runoob");
String Str4 = new String("RUNOOB");
boolean retVal; retVal = Str1.equals( Str2 );
System.out.println("返回值 = " + retVal ); retVal = Str3.equals( Str4);
System.out.println("返回值 = " + retVal ); retVal = Str1.equalsIgnoreCase( Str4 );
System.out.println("返回值 = " + retVal );
}
}
import java.io.*;

public class Test {
public static void main(String args[]) {
String Str1 = new String("runoob"); try{
byte[] Str2 = Str1.getBytes();
System.out.println("返回值:" + Str2 ); Str2 = Str1.getBytes( "UTF-8" );
System.out.println("返回值:" + Str2 ); Str2 = Str1.getBytes( "ISO-8859-1" );
System.out.println("返回值:" + Str2 );
} catch ( UnsupportedEncodingException e){
System.out.println("不支持的字符集");
}
}
}

public class Test {
public static void main(String args[]) {
String Str1 = new String("www.runoob.com");
char[] Str2 = new char[6]; try {
Str1.getChars(4, 10, Str2, 0);
System.out.print("拷贝的字符串为:" );
System.out.println(Str2 );
} catch( Exception ex) {
System.out.println("触发异常...");
}
}
}

public class Test {
public static void main(String args[]) {
String Str = new String("www.runoob.com");
System.out.println("字符串的哈希码为 :" + Str.hashCode() );
}
}

public class Main {
public static void main(String args[]) {
String string = "aaa456ac";
//查找指定字符是在字符串中的下标。在则返回所在字符串下标;不在则返回-1.
System.out.println(string.indexOf("b")); // indexOf(String str); 返回结果:-1,"b"不存在 // 从第四个字符位置开始往后继续查找,包含当前位置
System.out.println(string.indexOf("a",3));//indexOf(String str, int fromIndex); 返回结果:6 //(与之前的差别:上面的参数是 String 类型,下面的参数是 int 类型)参考数据:a-97,b-98,c-99 // 从头开始查找是否存在指定的字符
System.out.println(string.indexOf(99));//indexOf(int ch);返回结果:7
System.out.println(string.indexOf('c'));//indexOf(int ch);返回结果:7 //从fromIndex查找ch,这个是字符型变量,不是字符串。字符a对应的数字就是97。
System.out.println(string.indexOf(97,3));//indexOf(int ch, int fromIndex); 返回结果:6
System.out.println(string.indexOf('a',3));//indexOf(int ch, int fromIndex); 返回结果:6
}
}

public class Test {
public static void main(String args[]) {
String Str = new String("菜鸟教程:www.runoob.com");
String SubStr1 = new String("runoob");
String SubStr2 = new String("com"); System.out.print("查找字符 o 第一次出现的位置 :" );
System.out.println(Str.indexOf( 'o' ));
System.out.print("从第14个位置查找字符 o 第一次出现的位置 :" );
System.out.println(Str.indexOf( 'o', 14 ));
System.out.print("子字符串 SubStr1 第一次出现的位置:" );
System.out.println( Str.indexOf( SubStr1 ));
System.out.print("从第十五个位置开始搜索子字符串 SubStr1 第一次出现的位置 :" );
System.out.println( Str.indexOf( SubStr1, 15 ));
System.out.print("子字符串 SubStr2 第一次出现的位置 :" );
System.out.println(Str.indexOf( SubStr2 ));
}
}

吴裕雄--天生自然 JAVA开发学习:String 类的更多相关文章

  1. 吴裕雄--天生自然 JAVA开发学习:变量类型

    public class Variable{ static int allClicks=0; // 类变量 String str="hello world"; // 实例变量 pu ...

  2. 吴裕雄--天生自然 JAVA开发学习:java使用Eclipel连接数据库

    1:jar可到Mysql官网下载:地址Mysql 连接jar包.:https://dev.mysql.com/downloads/connector/j/如图,在下拉列表框中选择Platform In ...

  3. 吴裕雄--天生自然 JAVA开发学习:解决java.sql.SQLException: The server time zone value报错

    这个异常是时区的错误,因此只你需要设置为你当前系统时区即可,解决方案如下: import java.sql.Connection ; import java.sql.DriverManager ; i ...

  4. 吴裕雄--天生自然 JAVA开发学习:基础语法

    package test; public class temp { /* 第一个Java程序 * 它将打印字符串 Hello World */ public static void main(Stri ...

  5. 吴裕雄--天生自然 JAVA开发学习:Scanner 类

    import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { Scanne ...

  6. 吴裕雄--天生自然 JAVA开发学习:流(Stream)、文件(File)和IO

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //使用 BufferedReader 在控制台读取 ...

  7. 吴裕雄--天生自然 JAVA开发学习:方法

    /** 返回两个整型变量数据的较大值 */ public static int max(int num1, int num2) { int result; if (num1 > num2) re ...

  8. 吴裕雄--天生自然 JAVA开发学习:正则表达式

    import java.util.regex.*; class RegexExample1{ public static void main(String args[]){ String conten ...

  9. 吴裕雄--天生自然 JAVA开发学习:日期时间

    import java.util.Date; public class DateDemo { public static void main(String args[]) { // 初始化 Date ...

随机推荐

  1. 041-PHP把闭包函数当做参数传递

    <?php //把闭包函数当做参数传递 function demo($obj){ $obj('我爱PHP'); } # 传一个闭包过去 demo( function($txt){ echo $t ...

  2. centos7搭建kafka集群

    一.安装jdk 1.下载jdk压缩包并移动到/usr/local目录 mv jdk-8u162-linux-x64.tar.gz /usr/local 2.解压 tar -zxvf jdk-8u162 ...

  3. python 网页爬虫 基础篇

    首先要连接自己的数据库 import pymysql import requests #需要导入模块 db = pymysql.connect('localhost', 'root', '****** ...

  4. MySQLWorkbench注释

    不改变快捷键配置文件基础上 1. 通过菜单操作 Edit -> Format -> Un/comment 2. 键盘 (Windows 10, 其他操作系统未试过) Ctrl + /  ( ...

  5. Windows2008R2安装DNS和SQLServer200r2服务 (9.18第七天)

    原文网址:https://www.cnblogs.com/yankaohaitaiwei/p/11538205.html 二.IIS搭建web服务器 1.格式化D盘,一定要选择NTFS!!!不然后面添 ...

  6. CodeForces - 706C Hard problem(dp+字符串)

    题意:有n个字符串,只能将其逆转,不能交换位置,且已知逆转某字符串需要消耗的能量,问将这n个字符串按字典序从小到大排序所需消耗的最少能量. 分析:每个字符串要么逆转,要么不逆转,相邻两个字符串进行比较 ...

  7. Egret Engine 2D - Get Started

    Get Started     Egret 也支持在命令行完成编译,运行,发布等操作.在下面的教程中会穿插对应操作的命令行代码.   可新建游戏项目,也可建eui项目   这里包含默认的几个库,egr ...

  8. Python 自省指南

    原作者:Patrick K. O'Brien 什么是自省? 在日常生活中,自省(introspection)是一种自我检查行为.自省是指对某人自身思想.情绪.动机和行为的检查.伟大的哲学家苏格拉底将生 ...

  9. Codeforces_448C 分治

    昨晚CF碰到的题目,昨晚CF跪了啊啊啊 题意比较简单,给定一排挨在一起的板子,宽度都为1,高度不一,一个刷子宽度也是1,可以横着刷,也可以竖着刷,但是任何时刻刷子都要在板子上,也就是说,如果横向的时候 ...

  10. mysql第四篇:数据操作之单表查询

    单表查询 一.简单查询 -- 创建表 DROP TABLE IF EXISTS `person`; CREATE TABLE `person` ( `id` ) NOT NULL AUTO_INCRE ...