Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 21, 2021 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/c8136c4cee69fd22d2139cb492ec25e7 to your computer and use it in GitHub Desktop.
Save parzibyte/c8136c4cee69fd22d2139cb492ec25e7 to your computer and use it in GitHub Desktop.
/*
https://parzibyte.me/blog
* */
import java.util.AbstractMap;
class NombreConEdad {
String nombre;
int edad;
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public int getEdad() {
return edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
public NombreConEdad(String nombre, int edad) {
this.nombre = nombre;
this.edad = edad;
}
}
class Persona {
String nombre;
String apellido;
int edad;
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getApellido() {
return apellido;
}
public void setApellido(String apellido) {
this.apellido = apellido;
}
public int getEdad() {
return edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
public Persona(String nombre, String apellido, int edad) {
this.nombre = nombre;
this.apellido = apellido;
this.edad = edad;
}
}
public class Main {
public static NombreConEdad obtenerDatos() {
String nombre = "Luis";
int edad = 23;
return new NombreConEdad(nombre, edad);
}
public static Persona obtenerMasValores() {
String nombre = "Luis";
String apellido = "Cabrera";
int edad = 23;
return new Persona(nombre, apellido, edad);
}
public static String[] obtenerDosCadenas() {
String nombre = "Luis";
String apellido = "Cabrera";
return new String[]{nombre, apellido};
}
public static AbstractMap.SimpleEntry<String, Integer> obtenerSimpleEntry() {
String nombre = "Luis";
int edad = 23;
return new AbstractMap.SimpleEntry<>(nombre, edad);
}
public static void main(String[] args) {
String[] arreglo = obtenerDosCadenas();
String nombre = arreglo[0];
String apellido = arreglo[1];
AbstractMap.SimpleEntry<String, Integer> simpleEntry = obtenerSimpleEntry();
nombre = simpleEntry.getKey();
int edad = simpleEntry.getValue();
NombreConEdad nombreConEdad = obtenerDatos();
nombre = nombreConEdad.getNombre();
edad = nombreConEdad.getEdad();
Persona p = obtenerMasValores();
nombre = p.getNombre();
apellido = p.getApellido();
edad = p.getEdad();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment