没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
package com.anson.bz.oo.t06;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.logging.Logger;
import sun.util.logging.resources.logging;
public class TestString {
static Logger log=Logger.getLogger("com.anson.bz.oo.t06.TestString");
/**
* @param args
*/
public static void main(String[] args) {
String Str1="other words";
String Str2;
Str2="other words";
//--- 创建一个字符串
String Str3 = new String();
byte[] b=new byte[20];
/**
* 使用缺省字符集,把byte[20]转化成字符串
*/
String Str4=new String(b);
/**
* 使用指定字符集,把byte[20]转化成字符串
* 注意: Charset.forName("utf-8") 中的utf-8部分有可能抛出运行期的异常
*/
String Str5=new String(b,Charset.forName("utf-8"));
/**
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.util.logging.Logger;
import sun.util.logging.resources.logging;
public class TestString {
static Logger log=Logger.getLogger("com.anson.bz.oo.t06.TestString");
/**
* @param args
*/
public static void main(String[] args) {
String Str1="other words";
String Str2;
Str2="other words";
//--- 创建一个字符串
String Str3 = new String();
byte[] b=new byte[20];
/**
* 使用缺省字符集,把byte[20]转化成字符串
*/
String Str4=new String(b);
/**
* 使用指定字符集,把byte[20]转化成字符串
* 注意: Charset.forName("utf-8") 中的utf-8部分有可能抛出运行期的异常
*/
String Str5=new String(b,Charset.forName("utf-8"));
/**
* 使用所有的Object对象所拥有的 toString()方法得到字符串
*/
String Str6 = (new TestString()).toString();
String Str6x = String.valueOf(new TestString());
//--- 以上是我们得到一个字符串的常见方法 ,下面具体操作字符串
//连接字符串
String StrTest_1 ="ABC";
String StrTest_2 ="DEF";
String StrTest_3 =StrTest_1.concat(StrTest_2);
log.info("使用 concat() 方法的结果:\t"+StrTest_3);
String StrTest_4 =StrTest_1+StrTest_2;
log.info("与使用 + 方法的结果等同:\t"+StrTest_4);
//截取字符串
String StrTest_5 ="ABCDEF";
//substring(i)
//substring(i,p)
// 下标从0开始 ,substring 包含第一个 不包含最后一个
// [3,5)
String StrTest_6 =StrTest_5.substring(3);
String StrTest_7 =StrTest_5.substring(3,5);
log.info("对 ‘ABCDEF’ 进行 substring(3)的操作:\t"+StrTest_6);
log.info("对 ‘ABCDEF’ 进行 substring(3,5)的操作:\t"+StrTest_7);
try{
String StrTest_8 =StrTest_5.substring(3,8);
log.info("对 ‘ABCDEF’ 进行 substring(3,8)的操作:\t"+StrTest_8);
}catch(java.lang.StringIndexOutOfBoundsException ex){
log.severe(ex.getMessage());
}
//String = char[];
*/
String Str6 = (new TestString()).toString();
String Str6x = String.valueOf(new TestString());
//--- 以上是我们得到一个字符串的常见方法 ,下面具体操作字符串
//连接字符串
String StrTest_1 ="ABC";
String StrTest_2 ="DEF";
String StrTest_3 =StrTest_1.concat(StrTest_2);
log.info("使用 concat() 方法的结果:\t"+StrTest_3);
String StrTest_4 =StrTest_1+StrTest_2;
log.info("与使用 + 方法的结果等同:\t"+StrTest_4);
//截取字符串
String StrTest_5 ="ABCDEF";
//substring(i)
//substring(i,p)
// 下标从0开始 ,substring 包含第一个 不包含最后一个
// [3,5)
String StrTest_6 =StrTest_5.substring(3);
String StrTest_7 =StrTest_5.substring(3,5);
log.info("对 ‘ABCDEF’ 进行 substring(3)的操作:\t"+StrTest_6);
log.info("对 ‘ABCDEF’ 进行 substring(3,5)的操作:\t"+StrTest_7);
try{
String StrTest_8 =StrTest_5.substring(3,8);
log.info("对 ‘ABCDEF’ 进行 substring(3,8)的操作:\t"+StrTest_8);
}catch(java.lang.StringIndexOutOfBoundsException ex){
log.severe(ex.getMessage());
}
//String = char[];
剩余6页未读,继续阅读
资源评论
javaxianyu
- 粉丝: 4
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- delphi实现DBGrid全选和反选功能
- 25C11F41-2B2A-4D1A-AAA8-7C654526B129.pdf
- Android Studio Jellyfish(android-studio-2023.3.1.18-cros.deb)
- MVC+EF框架+EasyUI实现权限管理源码程序
- python第66-75天,Day66-75.rar
- python后端服务project-of-tornado.rar
- python测验,hello-tornado.rar
- 基于SpringBoot+Vue3快速开发平台、自研工作流引擎源码设计.zip
- docker安装部署全流程
- 基于树莓派的人脸识别系统python源码+项目部署说明+超详细代码注释.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功