To delve further into the issue of treatment of chains talk a little about the String class, perhaps for many people is a basic data type (rough) Java, however most are about objects of type string that allows us to manipulate text quickly and easily.
separately created objects of the String class can be initialized, among many other manner described in the Java documentation , as follows:
String string1, String string2 =
"This is a test message ";
string3 String = new String (" Hello World ");
String string4 = new String (string2);
course , as the other objects in Java, the String class has a number of methods for manipulating strings, some of these methods are:
char charAt ( int index) Returns the character
of a string in the position indicated by index. The index value must be a positive integer.
int compareTo ( String string)
Compare a string with another string, the return value is an integer that indicates the result of comparing two strings. This result is expressed by the ASCII value of character of the original string being compared with the second chain with an arithmetic subtraction. In summary, when comparing the characters of two strings with this method does the following:
- Suppose we have two strings that are declared and values:
string1 = "Sum"; ASCII Values : 83117109 97
string2 = "sum"; ASCII values: ; - 115 117 109 97
-------------------------------
-32 0 0 0
As can be seen, the result of the comparison between the first two characters ('S' and 's') we cast a negative value, which means that the chain compareTo "Sum" is less than " sum. " By detecting a change in the process of comparing the characters of two strings stops the execution of the method and returns the result. Int
compareToIgnoreCase ( String string)
Make a comparison between two strings ignoring if the strings are written in uppercase or lowercase . Like the compareTo method returns an integer value indicating the result of the comparison with the process described above.
String concat ( String string)
Allows concatenation of two strings.
boolean endsWith (String suffix)
Compares the contents of a string ends with the same sequence of characters that the indicated suffix.
boolean equals ( Object object)
Compare a string with the specified object.
boolean equalsIngoreCase ( String string)
Compares a string with another to see if they are identical and returns t rue if so, otherwise returns false .
byte [] getBytes () Converts
chain in a sequence of bytes storing the conversion back to an array of bytes.
void GetChars ( iniCadena int, int finCadena, char [] destination, int posDestino)
Copy the contents of a string delimited by start and end positions indicated iniCadena and finCadena with a target character array from the position indicated in posDestino.
int indexOf (int character)
Returns the index value of the specified character within a string.
int indexOf (int character, int index) Returns
index value of the specified character within a string starting the search beyond a specified index. Failure to find matches with the character you sought will return a -1 .
int indexOf ( String string)
Returns the value of the index where it begins a specified substring within a string.
int indexOf (String chain int index) Returns
index value which starts a specified substring within a string starting the search beyond a specified index. Failure to find matches to substring is searched returns a -1 .
int lastIndexOf ( int character)
Returns the value of the index of the last character found within a specified string.
int lastIndexOf (int character, int index) Returns the value
index the last character found within a specified search string beginning other than a specified index. Failure to find matches with the character you sought will return a -1 .
int lastIndexOf ( String string)
Returns the value of the index where it begins the last specified substring within a string.
int lastIndexOf (String chain int index) Returns
index value which starts the last substring specified within a string starting the search beyond a specified index. Failure to find matches to substring is searched returns a -1 .
int length ()
Returns the length of the string.
String replace ( char character, char nuevoCaracter)
Returns a string resulting from replacing all occurrences of the character specified by a new character.
String replaceAll ( String string, String replacement)
Returns a string resulting from replacing all occurrences of the string specified by a new string.
replaceFirst String (String chain String replacement) Replaces
first locate substring in a string with a replacement and return all the new chain.
boolean startsWith ( String prefix)
Checks if a string starts with the specified prefix.
boolean startsWith ( String prefix, int position)
Checks if the string starts with the prefix specified separately in an index.
String substring (int start) Returns a substring
apart from an index and length of the string until it invokes the method.
String substring (int beginning , int end) Returns a substring
apart from an initial rate to a final figure given.
char [] toCharrArray ()
Converts a string into an array of characters.
String toLowerCase ()
Convert string to lowercase. If the entire chain is originally lower returns the string in the same way, does not affect the method invocation.
String toUpperCase ()
Similar to toLowerCase () with the difference that this method converts a string to uppercase and returns the conversion.
String valueOf ( Object object)
Returns the string representation of an object.
Within the next file is performed test of the above methods.
With Pollitux and Computer ISCO for lodging.
0 comments:
Post a Comment