public final class String extends Object
Constructor and Description |
---|
String()
String
|
String(byte[] abyte0) |
String(byte[] abyte0,
int i)
Deprecated.
Method String is deprecated ?
|
String(byte[] abyte0,
int i,
int j) |
String(byte[] abyte0,
int i,
int j,
int k) |
String(byte[] bytes,
int ofs,
int len,
String name)
Convert byte[] to String using the appropriate byte encoding (UTF8 or ISO8859_1)/
|
String(byte[] bytes,
String name)
Convert byte[] to String using the appropriate byte encoding (UTF8 or ISO8859_1)
|
String(char[] ac) |
String(char[] ac,
int i,
int j) |
String(String s) |
String(StringBuffer stringbuffer) |
Modifier and Type | Method and Description |
---|---|
char |
charAt(int i) |
int |
compareTo(String s) |
String |
concat(String s) |
boolean |
contains(int ch)
Determines if the character (ch) appears in a string.
|
boolean |
contains(String needle)
Determines if a string (haystack) contains an occurrence of another string (needle).
|
static String |
copyValueOf(char[] ac) |
static String |
copyValueOf(char[] ac,
int i,
int j) |
boolean |
endsWith(String s) |
boolean |
equals(Object obj)
Compares two Objects for equality.
|
boolean |
equalsIgnoreCase(String s) |
static String |
format(String args,
Object... params)
Returns a formatted string using the specified format string and arguments.
|
byte[] |
getBytes() |
void |
getBytes(int start,
int stop,
byte[] abyte,
int ofs) |
byte[] |
getBytes(String s) |
void |
getChars(int i,
int j,
char[] ac,
int k) |
int |
hashCode()
Returns a hash code value for the object.
|
static int |
indexOf(char[] arr,
int ofs,
int len,
String str,
int idx)
Returns index of the supplied (@code String) segment in the character array subset
defined by an offset and length.
|
int |
indexOf(int i) |
int |
indexOf(String s) |
int |
indexOf(String s,
int i) |
int |
indexOfChar(int i,
int j) |
String |
intern()
Returns a canonical representation for the string object.
|
static int |
lastIndexOf(char[] arr,
int ofs,
int len,
String str,
int idx)
Returns the last index of the supplied (@code String) segment in the character array subset
defined by an offset and length.
|
int |
lastIndexOf(int i) |
int |
lastIndexOf(int i,
int j) |
int |
lastIndexOf(String s) |
int |
lastIndexOf(String s,
int i) |
int |
length() |
boolean |
regionMatches(boolean flag,
int i,
String s,
int j,
int k) |
boolean |
regionMatches(int i,
String s,
int j,
int k) |
String |
replace(char c,
char c1) |
boolean |
startsWith(String s) |
boolean |
startsWith(String s,
int i) |
String |
substring(int i) |
String |
substring(int i,
int j) |
char[] |
toCharArray() |
String |
toLowerCase() |
String |
toLowerCase(Locale locale) |
String |
toString()
Returns a string representation of the object.
|
String |
toUpperCase() |
String |
toUpperCase(Locale locale) |
String |
trim() |
static String |
valueOf(boolean flag) |
static String |
valueOf(char c) |
static String |
valueOf(char[] ac) |
static String |
valueOf(char[] ac,
int i,
int j) |
static String |
valueOf(double d) |
static String |
valueOf(float f) |
static String |
valueOf(int i) |
static String |
valueOf(long l) |
static String |
valueOf(Object obj) |
public String()
public String(String s)
s
- ?public String(StringBuffer stringbuffer)
stringbuffer
- ?public String(byte[] abyte0)
abyte0
- ?public String(byte[] abyte0, int i)
abyte0
- ?i
- ?public String(byte[] abyte0, int i, int j)
abyte0
- ?i
- ?j
- ?public String(byte[] abyte0, int i, int j, int k)
abyte0
- ?i
- ?j
- ?k
- ?public String(byte[] bytes, int ofs, int len, String name) throws UnsupportedEncodingException
bytes
- byte array to convertofs
- starting offset in the arraylen
- length of the byte arrayname
- encoding nameUnsupportedEncodingException
- if the encoding is not supportedpublic String(byte[] bytes, String name) throws UnsupportedEncodingException
bytes
- byte array to convertname
- encoding nameUnsupportedEncodingException
- ?public String(char[] ac)
ac
- ?public String(char[] ac, int i, int j)
ac
- ?i
- ?j
- ?public char charAt(int i)
i
- ?public int compareTo(String s)
s
- ?public static String copyValueOf(char[] ac)
ac
- ?public static String copyValueOf(char[] ac, int i, int j)
ac
- ?i
- ?j
- ?public boolean endsWith(String s)
s
- ?public boolean equals(Object obj)
Object
The equals
method implements an equivalence relation:
x
,
x.equals(x)
should return true
.
x
and
y
, x.equals(y)
should return
true
if and only if y.equals(x)
returns
true
.
x
,
y
, and z
, if x.equals(y)
returns true
and y.equals(z)
returns
true
, then x.equals(z)
should return
true
.
x
and y
, multiple invocations of x.equals(y)
consistently return true
or consistently return
false
.
x
, x.equals(null)
should return false
.
The equals method for class Object
implements the most
discriminating possible equivalence relation on objects; that is,
for any reference values x
and y
, this
method returns true
if and only if x
and
y
refer to the same object (x==y
has the
value true
).
equals
in class Object
obj
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Boolean.hashCode()
,
Hashtable
public boolean equalsIgnoreCase(String s)
s
- ?public byte[] getBytes()
public void getBytes(int start, int stop, byte[] abyte, int ofs)
start
- ?stop
- ?abyte
- ?ofs
- ?public byte[] getBytes(String s) throws UnsupportedEncodingException
s
- ?UnsupportedEncodingException
- ?public void getChars(int i, int j, char[] ac, int k)
i
- ?j
- ?ac
- ?k
- ?public int hashCode()
Object
java.util.Hashtable
.
The general contract of hashCode
is:
hashCode
method
must consistently return the same integer. This integer need not
remain consistent from one execution of an application to another
execution of the same application.
equals
method, then calling the hashCode
method on each of the
two objects must produce the same integer result.
hashCode
in class Object
Object.equals(java.lang.Object)
,
Hashtable
public boolean contains(String needle)
needle
- String that we are looking for.public boolean contains(int ch)
ch
- Character to search for.public int indexOf(int i)
i
- ?public int indexOfChar(int i, int j)
i
- ?j
- ?public int indexOf(String s)
s
- ?public int indexOf(String s, int i)
s
- ?i
- ?public static int indexOf(char[] arr, int ofs, int len, String str, int idx)
arr
- character array to be searchedofs
- offset in the character array at which to begin searchinglen
- length of the search segmentstr
- the (@code String) to findidx
- index in (@code String) at which the search string beginspublic String intern()
If s
and t
are strings such that
s.equals(t)
, it is guaranteed that
s.intern() == t.intern().
public int lastIndexOf(int i)
i
- ?public int lastIndexOf(int i, int j)
i
- ?j
- ?public int lastIndexOf(String s)
s
- ?public int lastIndexOf(String s, int i)
s
- ?i
- ?public static int lastIndexOf(char[] arr, int ofs, int len, String str, int idx)
arr
- character array to be searchedofs
- offset in the character array at which to begin searchinglen
- length of the search segmentstr
- the (@code String) to findidx
- index in (@code String) at which the search string beginspublic int length()
public boolean regionMatches(int i, String s, int j, int k)
i
- ?s
- ?j
- ?k
- ?public boolean regionMatches(boolean flag, int i, String s, int j, int k)
flag
- ?i
- ?s
- ?j
- ?k
- ?public String replace(char c, char c1)
c
- ?c1
- ?public boolean startsWith(String s)
s
- ?public boolean startsWith(String s, int i)
s
- ?i
- ?public String substring(int i)
i
- ?public String substring(int i, int j)
i
- ?j
- ?public char[] toCharArray()
public String toLowerCase()
public String toString()
Object
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object.
public String toUpperCase()
public String trim()
public static String valueOf(char c)
c
- ?public static String valueOf(double d)
d
- ?public static String valueOf(float f)
f
- ?public static String valueOf(int i)
i
- ?public static String valueOf(long l)
l
- ?public static String valueOf(boolean flag)
flag
- ?public static String valueOf(char[] ac)
ac
- ?public static String valueOf(char[] ac, int i, int j)
ac
- ?i
- ?j
- ?