I have this part of code:
System.out.print("nombre: ");
String nombre = leer.nextLine();
while(!nombre.equals("fin")){
mc.insertar(mc, 0);
System.out.print("nombre: ");
nombre = leer.nextLine();
}
for (int i = 0; i < mc.cantidad();i++) {
String aux = (String) mc.obtener(i);
System.out.println(aux + " - "+aux.length()+" caracteres");
}
By the time you get to this part (thanks to debug): String aux = (String) mc.obtener(i);
Send the following error message:
Exception in thread "main" java.lang.ClassCastException: Collections.CColection can not be cast to java.lang.String at Collections.CTest.main (CTest.java:27)
In the class CColeccion
the method obtener()
is like this:
public Object obtener(int i){
return datos[i];
}
The type of data I am working with is this: private Object datos[] = null;
(practice before moving to ArrayList
, generic and dynamic).
How do I convert it to String so that it gives me the name?