String クラス
- [内容]
- String 型データの処理を行います.String 型データは定数であり,生成された後は変えることはできません.StringBuffer 型データは,可変の文字列を扱います.
- [コンストラクタ]
- public String()
- 文字内容が空の String オブジェクト
- public String(char[] value)
- public String(char[] value, int offset, int count)
- 文字配列 value の中から,offset で始まる count 個の文字をとりだし,String オブジェクトを生成する.引数がないときは,文字配列全体を対象とする.
- public String(String original)
- public String(StringBuffer buffer)
- 引数で与えられたオブジェクトと同じ内容を持つ String オブジェクトの生成
- [主なメソッド]
- public int compareTo(String anotherString)
- public int compareToIgnoreCase(String str)
- 2 つの文字列を比較する.2 つの文字列が等しければ 0,辞書的に引数 anotherString より前に来るなら負の値,また,後ろに来るなら正の値を返す.compareToIgnoreCase の場合は,大文字と小文字の違いを無視する.
- public String concat(String str)
- 文字列 str を後ろに付けた新しい文字列を生成する
- public static String copyValueOf(char[] data)
- public static String copyValueOf(char[] data, int offset, int count)
- 文字配列 value の中から,offset で始まる count 個の文字をとりだし,String オブジェクトを生成する.引数がないときは,文字配列全体を対象とする.
- public boolean equals(Object anObject)
- public boolean equalsIgnoreCase(String anotherString)
- 2 つの文字列が等しいか否かを調べる.equalsIgnoreCase の場合は,大文字と小文字の違いを無視する.
- public static String format(String fmt, Object...args)
- C/C++ における printf と同様,引数を指定された書式( Formatter クラス参照)に従ってフォーマットした文字列を返す
- public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
- srcBegin から ( srcEnd - 1 ) までを,文字型配列 dts の dstBegin の位置にコピーする.
- public int hashCode()
- 文字列のハッシュコードを返す.
- public int indexOf(int ch)
- public int indexOf(int ch, int fromIndex)
- 文字列中で,引数の文字 ch が最初に現れた位置を返す.見つからなければ,-1 を返す.引数 fromIndex が指定されたときは,その位置から後ろを探す.
- public int indexOf(String str)
- public int indexOf(String str, int fromIndex)
- 文字列中で,引数の文字列 str が最初に現れた位置を返す.見つからなければ,-1 を返す.引数 fromIndex が指定されたときは,その位置から後ろを探す.
- public int lastIndexOf(int ch)
- public int lastIndexOf(int ch, int fromIndex)
- 文字列中で,引数の文字 ch が最後に現れた位置を返す.見つからなければ,-1 を返す.引数 fromIndex が指定されたときは,その位置から前を探す.
- public int lastIndexOf(String str)
- public int lastIndexOf(String str, int fromIndex)
- 文字列中で,引数の文字列 str が最後に現れた位置を返す.見つからなければ,-1 を返す.引数 fromIndex が指定されたときは,その位置から前を探す.
- public int length()
- 文字列の長さを返す
- public boolean regionMatches(int toffset, String other, int ooffset, int len)
- public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len)
- toffset から始まる長さ len の文字列と,文字列 other の toffset から始まる長さ len の文字列を比較する.ignoreCase を true にすると,大文字と小文字の違いを無視する.
- public String replace(char oldChar, char newChar)
- 文字列に現れるすべての oldChar を,newChar で置き換える
- public String[] split(String regex)
- 文字列を指定された正規表現に一致する位置で分割する
- public String substring(int beginIndex)
- public String substring(int beginIndex, int endIndex)
- 文字列の beginIndex から ( endIndex - 1 ) までの部分からなる新しい String オブジェクトを生成する.endIndex が入力されないときは,文字列の最後までを対象とする.
- public char[] toCharArray()
- 文字型配列に変換する
- public String toLowerCase()
- 小文字に変換する
- public String toUpperCase()
- 大文字に変換する
- public String trim()
- 両端のスペースを取り除く
- public static String valueOf(char[] data)
- public static String valueOf(char[] data, int offset, int count)
- 文字型配列内の,offset から count 個の文字からなる String オブジェクトを生成する
- public static String valueOf(double d)
- public static String valueOf(int i)
- 数値を文字列で表す
- [使用例]
- プログラム例は,String クラスの各メソッド等の使用例です.
- [参照]
- Character, Boolean, StringBuffer, Byte, Double, Integer, Short