SlideShare una empresa de Scribd logo
Clases de Envoltorio
o wrapper
Andrés Guzmán F
Tipos de datos de referencia
basados en tipos primitivos
• Cada tipo primitivo tiene su equivalente en un tipo de referencia o clase
• Dan mayor funcionalidad para operaciones de comprobaciones y conversiones
Tipo primitivo Clase Equivalente
byte Byte
short Short
int Integer
long Long
float Float
double Double
char Character
boolean Boolean
La Clase
Integer
• Cada tipo numérico tiene su propia clase de objetos.
• Así el tipo int tiene la clase Integer .
• Se implementan varios métodos útiles dentro de la clase envoltorio Integer
Integer i = Integer.valueOf(1234567);
String s = i.toString();
int j = i.intValue();
long l = i.longValue();
float f = i.floatValue();
double d = i.doubleValue();
int k = Integer.parseInt("2147483647");
La Clase
Integer
• Constantes de Integer
• Integer.MIN_VALUE
• Integer.MAX_VALUE
• Métodos estáticos
• String Integer.toString( int i, int base )
• String Integer.toString( int i )
• int Integer.parseInt( String s, int base )
• int Integer.parseInt( String s )
• Integer Integer.valueOf( String s, int base )
• Integer Integer.valueOf( String s )
La Clase
Integer
• Métodos de la instancia
• int intValue()
• long longValue()
• float floatValue()
• double doubleValue()
• String toString()
• int hashCode()
• boolean equals( Object obj )
• byte byteValue()
• short shortValue()
La Clase
Long
• Cada tipo numérico tiene su propia clase de objetos, así el tipo long tiene la clase Long .
• De la misma forma que con la clase Integer, se implementan muchas funciones útiles dentro
de los métodos de la clase Long .
Long l = Long.valueOf(2147483648L);
String s = l.toString();
int i = l.intValue();
long j = l.longValue();
float f = l.floatValue();
double d = l.doubleValue();
long k = Long.parseLong("9223372036854775807");
La Clase
Long
• Constantes de Long
• Long.MIN_VALUE
• Long.MAX_VALUE
• Métodos estáticos
• String Long.toString( long l, int base )
• String Long.toString( long l )
• long L.parseLong( String s, int base )
• long L.parseLong( String s )
• Long Long.valueOf( String s, int base )
• Long Long.valueOf( String s )
La Clase
Long
• Métodos de la instancia
• int intValue()
• long longValue()
• float floatValue()
• double doubleValue()
• String toString()
• int hashCode()
• boolean equals( Object obj )
• byte byteValue()
• short shortValue();
La Clase
Double
• Cada tipo numérico tiene su propia clase de objetos, así el tipo double tiene la clase Double .
• De la misma forma que con la clase Integer y Long, tenemos varias funciones útiles dentro de
los métodos de la clase Double.
Double d = Double.valueOf(3.14159);
String s = d.toString();
double j = d.doubleValue();
int i = d.intValue();
long l = d.longValue();
float f = d.floatValue();
double k = Double.parseDouble("314.159E-2");
La Clase
Double
• Constantes de Double
• Double.MIN_VALUE
• Double.MAX_VALUE
• Double.POSITIVE_INFINITY
• Double.NEGATIVE_INFINITY
• Métodos estáticos
• Double Double.valueOf( String s )
• Double Double.valueOf( double d )
• double Double.parseDouble(String s)
• String Double.toString(double d )
• boolean Double.isNaN( d )
• boolean Double.isInfinite( d )
• long Double.doubleToLongBits( d )
• double Double.longBitsToDouble( l )
La Clase
Double
• Métodos de la instancia
• boolean equals(Object o)
• String toString()
• int intValue()
• long longValue()
• float floatValue()
• double doubleValue()
• boolean isNaN()
• boolean isInfinite()
• byte byteValue()
• short shortValue()
La Clase
Float
• De la misma forma que con la clase Double, se han codificado varias funciones útiles dentro
de los métodos de la clase Float
Float f = Float.valueOf(3.14159F);
String s = f.toString();
double d = f.doubleValue();
int i = f.intValue();
long l = f.longValue();
float j = f.floatValue();
float k = Float.parseFloat("314.159E-2f");
La Clase
Character
• La clase Character también tiene métodos para comprobaciones y conversiones
Character c = Character.valueOf('A');
String s = c.toString();
char c2 = c.charValue();
char c3 = Character.toLowerCase(c);
boolean b = Character.isDigit(c);
boolean b2 = Character.isAlphabetic(c);
boolean b3 = Character.isUpperCase(c);
boolean b4 = Character.isLowerCase(c);
boolean b5 = Character.isLetter(c);
boolean b6 = Character.isSpaceChar(c);
boolean b7 = Character.isSpaceChar(' ');
boolean b8 = Character.isDigit('7');
La Clase
Character
Métodos estáticos
• Conversiones de caracteres
• Character Character.valueOf( c )
• char Character.toLowerCase( c )
• char Character.toUpperCase( c )
• Comprobaciones booleanas
• boolean Character.isLowerCase( c )
• boolean Character.isUpperCase( c )
• boolean Character.isDigit( c )
• boolean Character.isSpaceChar( c )
• boolean Character.isLetter( c )
• boolean Character.isAlphabetic( c )
La Clase
Character
• Métodos de la instancia
• String toString()
• char charValue()
• boolean equals(Object obj)
La Clase
Boolean
• El primitivo boolean también tienen su tipo asociado Boolean , aunque en este caso hay
menos métodos implementados que para el resto de las clases numéricas.
Boolean c = Boolean.valueOf(true);
Boolean c2 = Boolean.valueOf("true");
String s = c.toString();
boolean c3 = c.booleanValue();
La Clase
Boolean
• Constantes de Boolean
• Boolean.TRUE
• Boolean.FALSE
• Métodos de la instancia
• boolean booleanValue()
• String toString()
• boolean equals( Object obj )

Más contenido relacionado

PDF
Jyoc java-cap10 clases complementarias y enumerados
PPTX
Envolturas
PDF
Clase No.03 GENERALIDADES DEL LENGUAJE JAVA.pdf
PPTX
Tipos de datos
PPTX
Tipos de datos
PDF
Introducción a la programación y la informática. Tema 6
PDF
Sobrecarga de Métodos y Constructores.pdf
Jyoc java-cap10 clases complementarias y enumerados
Envolturas
Clase No.03 GENERALIDADES DEL LENGUAJE JAVA.pdf
Tipos de datos
Tipos de datos
Introducción a la programación y la informática. Tema 6
Sobrecarga de Métodos y Constructores.pdf

Similar a 6_clases_wrapper.pdf para trabajar con Java (20)

PPTX
CLASES STRING MATH TIME
PPT
LibreríAs De Java
PPTX
Certificación java 6 cap 3
DOCX
Conversión de tipos de datos
PPTX
Tipos de datos
PDF
Java - Sintaxis Básica 2015
PPTX
PPT
2.android java
PPT
Fund Java
PPT
Mule Librerias en Java
PDF
Jyoc java-cap06 la clase string
PPT
1 1 2 Datos Primitivas Y Objetos
 
PPT
1 introduccion a_java_2da_parte
PPTX
tipos de datos
DOCX
Clases predifinidas por .net
PPTX
Tipos de datos.java
PPTX
Tipos de datos.java
PPTX
Clasesyobjetos
DOC
Java clases dictadas
PPT
CLASES STRING MATH TIME
LibreríAs De Java
Certificación java 6 cap 3
Conversión de tipos de datos
Tipos de datos
Java - Sintaxis Básica 2015
2.android java
Fund Java
Mule Librerias en Java
Jyoc java-cap06 la clase string
1 1 2 Datos Primitivas Y Objetos
 
1 introduccion a_java_2da_parte
tipos de datos
Clases predifinidas por .net
Tipos de datos.java
Tipos de datos.java
Clasesyobjetos
Java clases dictadas
Publicidad

Último (9)

PPTX
Control de seguridad en los sitios web.pptx
PPTX
Conceptos basicos de Base de Datos y sus propiedades
PPTX
Tratará sobre Grafos_y_Arboles_Presentacion.pptx
PPTX
ORIGEN DE LA IA - GRADO 1102 INTELIGENCIA
PPTX
Implementación equipo monitor12.08.25.pptx
PPTX
Fundamentos de Python - Curso de Python dia 1
PDF
Clase 3 - Presentación visual (Insertando objetos visuales) POWER POINT.pdf
PDF
Presentacion de compiladores e interpretes
PDF
AutoCAD Herramientas para el futuro, Juan Fandiño
Control de seguridad en los sitios web.pptx
Conceptos basicos de Base de Datos y sus propiedades
Tratará sobre Grafos_y_Arboles_Presentacion.pptx
ORIGEN DE LA IA - GRADO 1102 INTELIGENCIA
Implementación equipo monitor12.08.25.pptx
Fundamentos de Python - Curso de Python dia 1
Clase 3 - Presentación visual (Insertando objetos visuales) POWER POINT.pdf
Presentacion de compiladores e interpretes
AutoCAD Herramientas para el futuro, Juan Fandiño
Publicidad

6_clases_wrapper.pdf para trabajar con Java

  • 1. Clases de Envoltorio o wrapper Andrés Guzmán F
  • 2. Tipos de datos de referencia basados en tipos primitivos • Cada tipo primitivo tiene su equivalente en un tipo de referencia o clase • Dan mayor funcionalidad para operaciones de comprobaciones y conversiones Tipo primitivo Clase Equivalente byte Byte short Short int Integer long Long float Float double Double char Character boolean Boolean
  • 3. La Clase Integer • Cada tipo numérico tiene su propia clase de objetos. • Así el tipo int tiene la clase Integer . • Se implementan varios métodos útiles dentro de la clase envoltorio Integer Integer i = Integer.valueOf(1234567); String s = i.toString(); int j = i.intValue(); long l = i.longValue(); float f = i.floatValue(); double d = i.doubleValue(); int k = Integer.parseInt("2147483647");
  • 4. La Clase Integer • Constantes de Integer • Integer.MIN_VALUE • Integer.MAX_VALUE • Métodos estáticos • String Integer.toString( int i, int base ) • String Integer.toString( int i ) • int Integer.parseInt( String s, int base ) • int Integer.parseInt( String s ) • Integer Integer.valueOf( String s, int base ) • Integer Integer.valueOf( String s )
  • 5. La Clase Integer • Métodos de la instancia • int intValue() • long longValue() • float floatValue() • double doubleValue() • String toString() • int hashCode() • boolean equals( Object obj ) • byte byteValue() • short shortValue()
  • 6. La Clase Long • Cada tipo numérico tiene su propia clase de objetos, así el tipo long tiene la clase Long . • De la misma forma que con la clase Integer, se implementan muchas funciones útiles dentro de los métodos de la clase Long . Long l = Long.valueOf(2147483648L); String s = l.toString(); int i = l.intValue(); long j = l.longValue(); float f = l.floatValue(); double d = l.doubleValue(); long k = Long.parseLong("9223372036854775807");
  • 7. La Clase Long • Constantes de Long • Long.MIN_VALUE • Long.MAX_VALUE • Métodos estáticos • String Long.toString( long l, int base ) • String Long.toString( long l ) • long L.parseLong( String s, int base ) • long L.parseLong( String s ) • Long Long.valueOf( String s, int base ) • Long Long.valueOf( String s )
  • 8. La Clase Long • Métodos de la instancia • int intValue() • long longValue() • float floatValue() • double doubleValue() • String toString() • int hashCode() • boolean equals( Object obj ) • byte byteValue() • short shortValue();
  • 9. La Clase Double • Cada tipo numérico tiene su propia clase de objetos, así el tipo double tiene la clase Double . • De la misma forma que con la clase Integer y Long, tenemos varias funciones útiles dentro de los métodos de la clase Double. Double d = Double.valueOf(3.14159); String s = d.toString(); double j = d.doubleValue(); int i = d.intValue(); long l = d.longValue(); float f = d.floatValue(); double k = Double.parseDouble("314.159E-2");
  • 10. La Clase Double • Constantes de Double • Double.MIN_VALUE • Double.MAX_VALUE • Double.POSITIVE_INFINITY • Double.NEGATIVE_INFINITY • Métodos estáticos • Double Double.valueOf( String s ) • Double Double.valueOf( double d ) • double Double.parseDouble(String s) • String Double.toString(double d ) • boolean Double.isNaN( d ) • boolean Double.isInfinite( d ) • long Double.doubleToLongBits( d ) • double Double.longBitsToDouble( l )
  • 11. La Clase Double • Métodos de la instancia • boolean equals(Object o) • String toString() • int intValue() • long longValue() • float floatValue() • double doubleValue() • boolean isNaN() • boolean isInfinite() • byte byteValue() • short shortValue()
  • 12. La Clase Float • De la misma forma que con la clase Double, se han codificado varias funciones útiles dentro de los métodos de la clase Float Float f = Float.valueOf(3.14159F); String s = f.toString(); double d = f.doubleValue(); int i = f.intValue(); long l = f.longValue(); float j = f.floatValue(); float k = Float.parseFloat("314.159E-2f");
  • 13. La Clase Character • La clase Character también tiene métodos para comprobaciones y conversiones Character c = Character.valueOf('A'); String s = c.toString(); char c2 = c.charValue(); char c3 = Character.toLowerCase(c); boolean b = Character.isDigit(c); boolean b2 = Character.isAlphabetic(c); boolean b3 = Character.isUpperCase(c); boolean b4 = Character.isLowerCase(c); boolean b5 = Character.isLetter(c); boolean b6 = Character.isSpaceChar(c); boolean b7 = Character.isSpaceChar(' '); boolean b8 = Character.isDigit('7');
  • 14. La Clase Character Métodos estáticos • Conversiones de caracteres • Character Character.valueOf( c ) • char Character.toLowerCase( c ) • char Character.toUpperCase( c ) • Comprobaciones booleanas • boolean Character.isLowerCase( c ) • boolean Character.isUpperCase( c ) • boolean Character.isDigit( c ) • boolean Character.isSpaceChar( c ) • boolean Character.isLetter( c ) • boolean Character.isAlphabetic( c )
  • 15. La Clase Character • Métodos de la instancia • String toString() • char charValue() • boolean equals(Object obj)
  • 16. La Clase Boolean • El primitivo boolean también tienen su tipo asociado Boolean , aunque en este caso hay menos métodos implementados que para el resto de las clases numéricas. Boolean c = Boolean.valueOf(true); Boolean c2 = Boolean.valueOf("true"); String s = c.toString(); boolean c3 = c.booleanValue();
  • 17. La Clase Boolean • Constantes de Boolean • Boolean.TRUE • Boolean.FALSE • Métodos de la instancia • boolean booleanValue() • String toString() • boolean equals( Object obj )