Docsity

Clase String: Propiedades y Métodos, Diapositivas de Programación Java

Vista previa parcial del texto

¡Descarga Clase String: Propiedades y Métodos y más Diapositivas en PDF de Programación Java solo en Docsity!

Kybele Research Group IV: Strings

Clase String

Allows the creation of objects which chains of chars

Basic Operators

String x, y, z; String myName = “Paul”; x = “Móstoles”; x = “Manuel Becerra”; // Móstoles desaparece y = x; // y contendrá Manuel Becerra x = “”; // x ahora es una cadena vacía String x, y; x = “Hola ”; y = “Mundo”; System.out.println(x+y); // x.concat(y) System.out.println(“La suma total es: ” + 25 + 30); System.out.println(“La suma total es: ” + (25 + 30)); ¿?

Clase String: Métodos

int length()

  • Length of the string

int indexOf(String cad)

  • This method returns the index within this string of the first occurrence of the specified character or - 1, if the character does not occur.

char charAt(int ind)

  • This method returns the character located at the String's specified index. The string indexes start from zero.

Clase String: Métodos Boolean equals(String cad)

  • This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object int compareTo(String cad)
  • This method compares two strings lexicographically
  • 0 if the argument is a string lexicographically equal to this string
  • < 0 if the argument is a string lexicographically greater than this string
  • 0 if the argument is a string lexicographically less than this string.

Clase String: Métodos

String substring(int indexInicial,

int indexFinal)

  • This method has two variants and returns a new string that is a substring of this string.
  • The substring begins with the character at the specified index and extends to - the end of this string or - up to endIndex – 1, if the second argument is given.

Kybele Research Group IV: Strings