java中String类的构造函数
String类中的构造函数
String(); 构造一个空字符串对象
String(byte[] bytes); 通过byte数组构造字符串对象
String(byte[] bytes,int offset,int length);通过byte数组,从offset开始,总共length长的字节构造字符串对象
String(char[] value); 通过char数组构造字符串对象
String(byte[] char,int offset,int length);通过char数组,从offset开始,总共length长的字节构造字符串对象
String(String original); 构造一个original的副本,拷贝一个original
String(StringBuffer buffer);通过StringBuffer数组构造字符串对象
public class StringClassTest {
public static void main(String[] args) {
// 字节数组
byte[] bArray = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
// 字符数组
char[] cArray = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
//声明一个StringBuffer
StringBuffer strbuf = new StringBuffer("strbuf");
// 实例一个String对象
String str = new String("str abcd");
//实例一个String对象 通过一个btye数组构造字符串对象(字节数组)
String strb = new String(bArray);
//实例一个String对象 通过一个char数组构造字符串对象(字符数组)
String strc = new String(cArray);
//实例一个String对象 通过一个char数组构造字符串对象(字节数组,开始的数据,截得数据长度)
String strbIndex = new String(bArray, 1, 5);
//实例一个String对象 通过一个char数组构造字符串对象(字符数组,开始的数据,截得数据长度)
String strcIndex = new String(cArray, 1, 2);
//实例一个
相关文档:
public static String byteToString(byte src)
{
String desc = null;
int i = 0; //取1个字节
i = src&0xFF;
desc = Integer.toHexString(i);
if (desc.length() == 1)
......
public static void main(String[] args) {
String DATE_FORMAT = "yyyy-MM-dd";
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
DATE_FORMAT);
Calendar c1 = Calendar.getInstance();
c1.set(1999, 0, 14);
&n ......
用三种方法来实现字符串的反转
/**
* @(#)ReverseString.java
*
* ReverseString application
*
* @author
* @version 1.00 2010/4/20
*/
import java.util.*;
import java.io.*;
public class ReverseString {
public static void main(String[] args) throws IOException{
......
本文出自 “唐大老师” 博客,请务必保留此出处http://tscjsj.blog.51cto.com/412451/84561
public class Bubble {
// 冒泡排序函数1
public static void bubbleSort1(Comparable []data){
int position,scan;
Comparable temp;
for(position = data.length-1;position>=0;position--){
......
首先看清楚几种常用的字符集编码(java语言是采用unicode字符集编码来表示字符与字符串的):
ASCII(American Standard Code for Information Interchange,美国信息互换标准代码),是基于常用的英文字符的一套电脑编码系统。我们知道英文中经常使用的字符、数字符号被计算机处理时都是以二进制码的形式出现的。这种二进 ......