자바 string 클래스 방법 깊이 분석
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Locale;
import java.util.Date;
import java.util.regex.PatternSyntaxException;
import javax.xml.crypto.Data;
public class Stringxuexi {
public static void main(String[] argc)
{
//charAt(int index) index Unicode
String strCom = "JAVA ";
System.out.println(strCom.charAt(4));
//codePointAt(int index) index Unicode
strCom = "I like JAVA ,too";
System.out.println(strCom.codePointAt(8));
//codePointBefore index-1 Unicode
System.out.println(strCom.codePointBefore(2));
//codePointCount(int beginIndex,int endIndex) Unicode
System.out.println(strCom.codePointCount(0, 3));
//compareTo(String str)
// , , ,
// , k , k
// char , ,
System.out.println(strCom.compareTo("I like PHP"));
System.out.println(strCom.compareTo("I like JAVA too"));
//compareToIgnoreCase(String str)
System.out.println(strCom.compareToIgnoreCase("I Like PHP"));
//concat(String str) , 0,
// , String
System.out.println(strCom.equals(strCom.concat("")));
System.out.println(strCom.concat(strCom));
//contains(CharSequence s) char
System.out.println(strCom.contains("JAVA"));
//valueOf(char []data) ,
char [] array={' ',' '};
System.out.println(String.valueOf(array));
//valueOf(char[] data,int offset,int count) offset count
//
System.out.println(String.valueOf(array, 0, 1));
//endwith(String suffix)
System.out.println(strCom.endsWith("JAVA"));
//equals(object obj) String String , true, false
System.out.println(strCom.equals("I like JAVA"));
//equalsIgnoreCase(String anotherString) // , equals
System.out.println(strCom.equalsIgnoreCase("I Like JAva"));
//format(String format,Object ...args)
//%d
//%o
//%x %X
System.out.println(String.format("%e %x %o %d %a %% %n", 15.000,15,15,15,15.0));
//format(Locale l,String format,Object ... args)
//
//%te
//%tb
//%tB
//%tA
//%ta
//%tc
//%tY 4
//%ty
//%tm
//%tj
//%td
Date date = new Date();
Locale form = Locale.CHINA;
String year = String.format(form, "%tY", date);
String month = String.format(form, "%tm", date);
String day = String.format(form, "%td", date);
System.out.println(" : "+ year + " "+month+" "+day+" ");
System.out.println(String.format(form, "%tc", date));
//byte[] getBytes() byte
byte[] str = strCom.getBytes();
for (int i = 0;i < str.length;i++)
System.out.print(str[i]+" ");
//getBytes(Charset charset)
//getBytes(String string)
//
try {
str = strCom.getBytes(Charset.defaultCharset());
for (int i = 0; i < str.length; i++)
System.out.println(str[i] + " ");
} catch (UnsupportedCharsetException e) {
// TODO: handle exception
e.printStackTrace();
}
//getchars(int srcBegin,int srcEnd,char[] dst,int dstBegin)
//
char[] dst = new char[10];
strCom.getChars(0, 10, dst, 0);
for (int i = 0; i < dst.length;i++)
System.out.print(dst[i]);
System.out.println();
//hashCode() ,String
//s[0]*31^(n-1)+s[1]*31^(n-2)+...+s[n-1]
// 0
System.out.println(strCom.hashCode());
//indexOf(int ch) ,ch , , -1
System.out.println(strCom.indexOf('A'));
//indexOf(int ch,int fromIndex) //
//fromIndex , , 0 , , -1
System.out.println(strCom.indexOf('A', 9));
//indexOf(String str)
//indexOf(String str,int fromIndex)
//
System.out.println(strCom.indexOf("JAVA"));
//intern()
// intern , String ,
// , String
// 。
String strCom2 = new String("I like JAVA");
System.out.println(strCom == strCom2);
System.out.println(strCom.endsWith(strCom2));
System.out.println(strCom.compareTo(strCom2));
System.out.println(strCom.intern() == strCom2.intern());
String s1 = new String(" ,Java ");
String s2 = new String(" ,") + "Java ";
System.out.println(s1==s2);
System.out.println(s1.intern()==s2.intern());
// indexOf, fromIndex , fromIndex
System.out.println(strCom.lastIndexOf('A'));
System.out.println(strCom.lastIndexOf('A',10));
System.out.println(strCom.lastIndexOf("JAVA"));
System.out.println(strCom.lastIndexOf("JAVA", 10));
//
System.out.println(strCom.length());
//matchs(String regex)
try {
String regex = "1234";
System.out.println(regex.matches("//d{4}"));
System.out.println(regex.replaceAll("//d{4}", "chen"));
System.out.println(regex.replaceFirst("//d{4}", "chen"));
} catch (PatternSyntaxException e) {
// TODO: handle exception
e.printStackTrace();
}
// offsetByCodePoints(int index,int codePointOffset)
// index codePointOffset
System.out.println(strCom.offsetByCodePoints(7, 4));
// , true
System.out.println(strCom.regionMatches(true, 0, "I lIke", 0, 3));
System.out.println(strCom.regionMatches(0, "I like", 0, 3));
System.out.println(strCom.replace('A', 'a'));
System.out.println(strCom.replace("JAVA", "PHP"));
//String[] split(String regex,int limit)
// ,limit
String[] info = strCom.split(" ,");
for (int i = 0; i < info.length;i++)
System.out.println(info[i]);
info = strCom.split(" ", 2);
for (int i = 0; i < info.length;i++)
System.out.println(info[i]);
//startsWith(String prefix,int toffset)//
//toffset false
System.out.println(strCom.startsWith("I"));
System.out.println(strCom.startsWith("I",-1));
//CharSequeuece subSequeuece(int beginIndex,int endIndex)
//
System.out.println(strCom.subSequence(2, 6));
//String substring(int beginindex,int endIndex)
//
System.out.println(strCom.substring(2));
System.out.println(strCom.substring(2, 6));
//toCharArray()
char[] str1 = strCom.toCharArray();
for (int i = 0; i < str1.length;i++)
System.out.print(str1[i]+" ");
System.out.println();
//toLowerCase(Locale locale) /
System.out.println(strCom.toLowerCase());
System.out.println(strCom.toUpperCase());
System.out.println(strCom.toUpperCase(form));
System.out.println(strCom.toLowerCase(form));
//trim()
System.out.println((" "+strCom).trim());
//valueOf()
System.out.println(String.valueOf(true));
System.out.println(String.valueOf('A'));
System.out.println(String.valueOf(12.0));
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.