/* CLASE QUE MUESTRA EN CONSOLA LOS RESULTADOS
* DE ALGUNOS MÉTODOS QUE MANIPULAN CADENAS */
public class Cadenas
{
public static void main(String[] args)
{
String texto1 = "PolloDavid"; // Declaración simple
String texto2 = new String("PolloMiliuco"); // Usando un constructor
System.out.println( "\nLa primera cadena de texto es :\n" );
System.out.println( "\t"+texto1 );
System.out.println( "\nLa segunda cadena de texto es :\n" );
System.out.println( "\t"+texto2 );
System.out.println( "\nConcatenamos con texto2 delante: " + texto2 + texto1 );
System.out.println( "Concatenamos con texto1 delante: " + texto1 + texto2 );
System.out.println( "Concatenamos cadenas con enteros: " + texto1 + " " + 5 + " " + 23.5 );
System.out.println( "\nLa longitud de la texto2 es: " + texto2.length() );
System.out.println( "La segunda letra de texto2 es: " + texto2.charAt(1) );
System.out.println( "Tres letras de texto2 desde la posicion 2: " + texto2.substring(2,5) );
System.out.println( "\nLa letra l aparece por primera vez en texto2 en el indice: " + texto2.indexOf("l") );
System.out.println( "La letra l aparece por ultima vez en texto2 en el indice: " + texto2.lastIndexOf("l") );
texto2 = texto2.replace("c", "q");
System.out.println( "\nCambiamos c por q en texto2: " + texto2);
System.out.println( "\nLa cadena texto2 en mayusculas: " + texto2.toUpperCase() );
System.out.println( "La cadena texto2 en minusculas: " + texto2.toLowerCase() );
System.out.println( "\nComparamos texto1 y texto2: " + texto1.compareTo(texto2) );
if (texto1.compareTo(texto2) < 0)
System.out.println( "\tTexto1 es mas corto que texto2" );
StringBuffer texto3 = new StringBuffer("Otra cadena");
texto3.append(" nueva");
System.out.println( "\nTexto 3 es: " + texto3 );
texto3.insert(6, "1");
System.out.println( "Intercalando un 1 en la posicion 6: " + texto3 );
texto3.reverse();
System.out.println( "Y ahora texto3 invertido: " + texto3 +"\n");
}
}