Vergleichen von Objekten
Wie vergleiche ich zwei Zeichenketten?
String ref1 = new String ("http://www.Bastie.de/java/howto/index.html");
String ref2 = ref1;
if (ref1 == ref2){
System.out.println("Gleiche Referenz!");
}
else {
throw new RuntimeException ("Ätsch");
}
String inhalt1 = new String ("Make Java - Performance");
String inhalt2 = new String ("Make Java - Performance");
String inhalt3 = new String ("MAKE JAVA - PERFORMANCE");
if (inhalt1 == inhalt2){
throw new RuntimeException ("Nö ich hab 'ne andere Referenz");
}
if (inhalt1.equals(inhalt2)){
System.out.println ("Ja der Inhalt ist identisch!");
}
else {
throw new RuntimeException ("Hupsi");
}
if (inhalt2.equalsIgnoreCase(inhalt3)){
System.out.println ("Ja der Inhalt ist identisch, wenn ich die "
+"Groß- / Kleinschreibung ignoriere!");
}
else {
throw new RuntimeException ("Guter Versuch...");
}
String inhalt4 = new String ("MAKE JAVA _ PERFORMANCE");
if (inhalt3.equalsIgnoreCase(inhalt4)){
throw new RuntimeException ("Nee - ist nicht die kleine Version von _");
}
else {
System.out.println ("Nein es gibt eben keine Groß- / Kleinschreibung "
+"bei Nichtbuchstaben!");
}
all rights reserved © Bastie - Sebastian Ritter @:
w³: http://www.Bastie.de
Diese Seite ist Bestandteil der
Internetpräsenz unter http://www.Bastie.de
Java
Cobol
Software
Resourcen
Service
Links
Über mich
Zum Gästebuch
Forum