8.582
Bearbeitungen
Jneug (Diskussion | Beiträge) |
Jneug (Diskussion | Beiträge) |
||
| Zeile 408: | Zeile 408: | ||
=== Datentyp-Klassen === | === Datentyp-Klassen === | ||
==== java.lang.String ==== | |||
{| {{prettytable}} | {| {{prettytable}} | ||
! Beschreibung | ! Beschreibung | ||
! Signatur | |||
! Beispiel | ! Beispiel | ||
|- | |- | ||
| ''' | | Anzahl Zeichen in der Zeichenkette. | ||
| {{nowrap|'''int length()'''}} | |||
| <syntaxhighlight lang="java"> | |||
String text = "Hallo, Welt!"; | |||
int zeichen = text.length(); // 12 | |||
</syntaxhighlight> | |||
|- | |||
| Wandelt alle Zeichen in Großbuchstaben um. | |||
| {{nowrap|'''String toUpperCase()'''}} | |||
| <syntaxhighlight lang="java"> | |||
String text = "Hallo, Welt!"; | |||
String upper = text.toUpperCase(); // HALLO, WELT! | |||
</syntaxhighlight> | |||
|- | |||
| Wandelt alle Zeichen in Kleinbuchstaben um. | |||
| {{nowrap|'''String toLowerCase()'''}} | |||
| <syntaxhighlight lang="java"> | |||
String text = "Hallo, Welt!"; | |||
String upper = text.toLowerCase(); // hallo, welt! | |||
</syntaxhighlight> | |||
|- | |||
| Findet die Position im String, an der der Text <code>suchen</code> zum ersten Mal vorkommt. Kommt der Text gar nicht vor, dann wird <code>-1</code> zurück gegeben. Das erste Zeichen hat den Index <code>0</code>. | |||
| {{nowrap|'''int indexOf( String suchen )'''}} | |||
| <syntaxhighlight lang="java"> | | <syntaxhighlight lang="java"> | ||
String text = "Hallo, Welt!"; | |||
int position = text.indexOf(","); // 5 | |||
text.indexOf("Foo"); // -1 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |} | ||