From a String, "123-654321"
, what I want is to split it into two Strings:
string1=123
string2=654321
From a String, "123-654321"
, what I want is to split it into two Strings:
string1=123
string2=654321
I have my Java program and I get a NullPointerException and I have seen other questions but they are from people with other programs and it does not work for my program and I want to leave you here the 2,000 lines of my program so that you can solve the problem for me but people do not let.
Look, my program is like this
Object a = null;
// 500 líneas de código
// Dentro de un bucle, dentro de un if, dentro de un for...
a = algunaFuncionDeMilLineasQueNoTeVoyAMostrar(
parámetrosDeLosQueNoTeDiréElValor)
// Cerrando for, cerrando if, cerrando bucle.
// Otras 500 líneas de código
// Una de estas líneas lanza el NPE, pero no te diré cuál.
a.toString();
z.hazAlgunaCosa();
x.haxY().hazM().cuantoFaltaParaLasVacaciones().andaMiraUnPatoQuePasaPorAhi();
It's wrong? Why isn't there a one-size-fits-all solution for NullPointerExceptions (NPEs) if they happen so often?
Definitive Guide to Type Conversion in Java
String
toInteger
Integer
toString
char
toString
String
tochar
String
toDouble
Double
toString
String
toFloat
Float
toString
String
toBoolean
Boolean
toString
In the code I see many times x++
in loops, but sometimes I find ++x
.
Is there a difference between these two expressions?
I am creating a mini game where the user tries to guess a name. But when I want to compare two text strings to see if they are the same it doesn't seem to work.
final String miNombre = "Jordi";
Scanner input = new Scanner(System.in);
System.out.println("Adivina mi nombre: ");
while (true) {
String intento = input.next();
if(intento == miNombre) {
System.out.println("Acertaste!");
break;
} else {
System.out.println("Intentalo de nuevo!");
}
}
EXIT:
Adivina mi nombre:
manuel
Intentalo de nuevo!
jordi
Intentalo de nuevo!
Jordi
Intentalo de nuevo!