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. 12.Python的高级语法和用法

    # from enum import Enum # 枚举 # class VIP(Enum): # YELLOW = # YELLOW_ALIAS = # 别名 # GREEN = # BLACK = ...

  2. Django 模板渲染

    模板语言 {{ 变量 }} {% 逻辑 %} {{ 变量 }} {{ 变量 }}中的点号 用于取出字典/列表等类型数据的值 {{ list.2 }} 获取列表list中索引为2的值 {{ dict.n ...

  3. 一百零六、SAP的OOP面向对象编程,OO-ALV的简介

    面向对象编程,如图 基本概念: 1.对象(Object)是一个现实实体的抽象.一个对象可被认为是一个把数据(属性)和程序(方法)封装在一起的实体,这个程序产生该对象的动作或对它接受到的外界信号的反应. ...

  4. 箭头函数arrow funtion

    1.定义一个匿名函数常规语法: function (x) { return x * x; } 2.该函数使用箭头函数可以使用仅仅一行代码搞定! x => x * x 箭头函数相当于匿名函数,并且 ...

  5. selenium2Library报错: Unexpected error launching Internet Explorer. Browser zoom level was set to 119%. It should be set to 100%

    Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected ...

  6. 编程入门-Eclipse项目导出和导入

    编程入门-Eclipse项目导出和导入 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.导出项目 1>.如下图所示,在项目目录上右击鼠标,依次点击"Export& ...

  7. UVA - 11400 Lighting System Design(照明系统设计)(dp)

    题意:共有n种(n<=1000)种灯泡,每种灯泡用4个数值表示.电压V(V<=132000),电源费用K(K<=1000),每个灯泡的费用C(C<=10)和所需灯泡的数量L(1 ...

  8. svg教程

    实例 <html> <body> <h1>My first SVG</h1> <svg style="border: 1px solid ...

  9. BGP的地址聚合

    aggregate-address ip make——多用于地址聚合命令. 但,因此很容易产生路由环路. 所以多加一个参数. as-set as-set,可以是BGP聚合路不丢失原来的AS-Path属 ...

  10. 十五、CI框架之自动加载数据库

    一.在config的autoload.php文件中,如果写入以下代码,那么在控制器中无需再次加载数据库了,相当于全局自动加载数据库了 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码 ...