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. MVC 中引用Angularjs

    首先在Maname NuGet Packages中 安装相应的包,我用的是作者为 AngualrJS Team的 随后在相应的Scripts中会出现对应文件. 如果只在某一个页面中使用Angualrj ...

  2. bool之regexp正则注入(原理详解)

    感谢原创博主的文章,在此致敬.本文转自:http://www.cnblogs.com/lcamry/articles/5717442.html 我们都已经知道,在MYSQL 5+中 informati ...

  3. spring boot 连接Mysql介绍

    Spring Boot 集成教程 Spring Boot 介绍 Spring Boot 开发环境搭建(Eclipse) Spring Boot Hello World (restful接口)例子 sp ...

  4. Django static配置

    STATIC_URL = '/static/' # HTML中使用的静态文件夹前缀 STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static&q ...

  5. 《ES6标准入门》(阮一峰)--2.let 和 const 命令

    1.let命令 基本用法 let只在命令所在的代码块内(花括号内)有效. for循环的计数器,就很合适使用let命令. //var var a = []; for (var i = 0; i < ...

  6. poj 3693 Maximum repetition substring

    呵呵呵呵呵呵呵呵呵呵,sb(神犇)题看了一天,还是不懂 题目要求的是最多重复的,那么就来找重复的,可以先枚举一个重复的单元(比如ababab,就枚举ab)的长度, 然后再原串中,会有ch[0],ch[ ...

  7. 详解CentOS7安装配置vsftp搭建FTP

    安装配置vsftpd做FTP服务,我们的Web应用使用git管理进行迭代,公共文件软件存储使用开源网盘Seafile来管理,基本够用.想不到FTP的使用的场景,感觉它好像老去了,虽然现在基本没有用到这 ...

  8. 利用方法HttpUtility.HtmlEncode来预处理用户输入

    利用方法HttpUtility.HtmlEncode来预处理用户输入.这样能阻止用户用链接注入JavaScript代码或HTML标记,比如//Store/Broswe?Genre=<script ...

  9. c 转二进制

    int nData = 1568;//转二进制 for (int i = sizeof(int) * 8 - 1; i >= 0; i--){ if ((nData >>i) &am ...

  10. java AES加解密

    AES加解密工具类 package com.yan.demo; import org.apache.commons.lang3.StringUtils; import sun.misc.BASE64D ...