Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Carcter
! Valores
numricos
que
se
usan
para
representar
caracteres
(letras,
nmeros,
smbolos)
usando
la
tabla
Unicode
La clase String
! Tipo char
String
Generacin
! Su valor es inmutable
! Nunca va a cambiar
Es un objeto
Mtodos
h
o
l
a
! Tiene
varios:
! de
instancia
! de
clase
c a s a
!
!
!
!
!
!
!
!
!
charAt()
concat()
equals()
length()
replace()
substring()
toCharArray()
toLowerCase()
toUpperCase()
13/02/12
String
concat(String
s)
! Devuelve
un
nuevo
string
adjuntando
el
valor
del
string
pasado
como
parmetro
al
valor
del
string
actual.
String x = hola;!
System.out.println( x.concat( mundo!) );!
boolean
equals(String
s)
! Devuelve
verdadero
si
el
valor
del
string
pasado
es
el
mismo
que
el
actual
String x = hola;!
Comparando
Strings
! Qu
pasara
si
uso
==
?
h
o
l
a
String uno = new String(hola);!
String otro = new String(hola);!
!
System.out.println(uno==otro);?!
Comparando
Strings
! Y
con
esto?
String uno = hola;!
String otro = hola;!
!
System.out.println(uno==otro);?!
h o l a
! Por
qu?
! Eciencia
true!
13/02/12
int length()
String x = hola;!
h
o
l
a
String x = oxoxox;!
System.out.println( x.replace(o,O) )!
String x =holamundo;!
System.out.println( x.substring(0,3) );!
La salida es:
// hola!
OxOxOx
String
toLowerCase()
String
toUpperCase()
char[] toCharArray()
String x = hola;!
String x = hola;!
Imprimira
HOLA
13/02/12
Encadenamiento de llamadas
StringBuilder
String x = "abc";
String y = x.concat("def").toUpperCase().replace('C','x');
! Muy ineciente
Creacin
Mtodos importantes
! append
! charAt
! setCharAt
! delete
! insert
! reverse
! toString
StringBuilder append(String s)
sb.append(mundo);
System.out.println(sb);
13/02/12
StringBuilder x = new StringBuilder(avion);!
x.setCharAt(1,V);!
System.out.println( x);!
// aVion!
StringBuilder reverse()
StringBuilder sb = new
StringBuilder(01234);!
sb.insert(3,-);!
System.out.println(sb);!
sb.reverse();!
// Devolvera 012-34!
System.out.println( sb);!
//
Devolvera
43210
String
toString()
! Devuelve
un
String
con
los
caracteres
del
StringBuer
StringBuilder sb = new StringBuilder(test);!
String s = sb.toString();!
System.out.println( s);!