吴裕雄--天生自然 JAVA开发学习:String 类
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 类的更多相关文章
- 吴裕雄--天生自然 JAVA开发学习:变量类型
public class Variable{ static int allClicks=0; // 类变量 String str="hello world"; // 实例变量 pu ...
- 吴裕雄--天生自然 JAVA开发学习:java使用Eclipel连接数据库
1:jar可到Mysql官网下载:地址Mysql 连接jar包.:https://dev.mysql.com/downloads/connector/j/如图,在下拉列表框中选择Platform In ...
- 吴裕雄--天生自然 JAVA开发学习:解决java.sql.SQLException: The server time zone value报错
这个异常是时区的错误,因此只你需要设置为你当前系统时区即可,解决方案如下: import java.sql.Connection ; import java.sql.DriverManager ; i ...
- 吴裕雄--天生自然 JAVA开发学习:基础语法
package test; public class temp { /* 第一个Java程序 * 它将打印字符串 Hello World */ public static void main(Stri ...
- 吴裕雄--天生自然 JAVA开发学习:Scanner 类
import java.util.Scanner; public class ScannerDemo { public static void main(String[] args) { Scanne ...
- 吴裕雄--天生自然 JAVA开发学习:流(Stream)、文件(File)和IO
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //使用 BufferedReader 在控制台读取 ...
- 吴裕雄--天生自然 JAVA开发学习:方法
/** 返回两个整型变量数据的较大值 */ public static int max(int num1, int num2) { int result; if (num1 > num2) re ...
- 吴裕雄--天生自然 JAVA开发学习:正则表达式
import java.util.regex.*; class RegexExample1{ public static void main(String args[]){ String conten ...
- 吴裕雄--天生自然 JAVA开发学习:日期时间
import java.util.Date; public class DateDemo { public static void main(String args[]) { // 初始化 Date ...
随机推荐
- IDEA 分屏显示
效果: 步骤: 对着某个标签页单击右键,选择Split Vertically或者Split Horizontally即可.
- 八十二、SAP中的ALV创建之一,新建一个程序
一.创建一个ALV的程序 二.填写程序属性 三.保存到本地对象 四.来到代码区,这样一个新工程就创建好了,我们后续来写相关的创建代码
- 了解C#
了解C C#能编写那些程序 Windows桌面应用程序 桌面应用有自己独立的进程与操作系统进行消息通讯,操作系统对事件进行检测,传递给桌面应用进程,桌面应用进程对这些消息进行解释,处理后,把处理结果u ...
- 本地的jar包导入到maven仓库
需要引入本地jar,然后百度跟着教程实现了,做个记录加深印象.https://www.cnblogs.com/lixuwu/p/5855031.html 1首先找到要传入maven的jar包(放在一个 ...
- jvm 性能监控与linux常用命令
linux日常的运维 .Java开发 管理监控命令 ,较为浅显,欢迎提意见,我将在后面持续补充.
- Linux基础命令层级图-01
Linux基础命令层级图-01:
- python---函数作用域
1.作用域 local:局部作用域 E(Enclosing):闭包函数外的函数中 G(global): 全局作用域 B(Build-in):內建作用域 查找变量的顺序,从上到下 2.函数内的变 ...
- Diligent Engine学习笔记初衷
2020年过去一个月了,回首过去的一年,工作确实很忙,但是自己个人的技术也没得到什么成长,项目当中一些比较难搞的问题也没得到更深入的研究.思来想去,希望新的一年能改变自己的工作方式,将工作上的事物进一 ...
- Session简单介绍
Session 会话 , Session是基于Cookie的一种会话机制. Cookie是服务器返回一小份数据给客户端,并且存放在客户端上. Session是,数据存放在服务器端. 常用API //得 ...
- 吴裕雄--天生自然 PHP开发学习:常量
<?php // 区分大小写的常量名 define("GREETING", "欢迎访问 Runoob.com"); echo GREETING; // 输 ...