Работа со строками
Автор Kosenkov На чтение 1 мин Просмотров 180 Опубликовано Обновлено
Конвертация в строку и обратно
long fromString = Long . parseLong (" 12345 ");
String fromLong = Long . toString (12345);
String concatenation = " area " + 51;
String hello = " Hello ";
String specialChars = "\r\n\t \"\\ ";
String empty = "";
char [] charArray = {’a’, ’b’, ’c’};
String string = new String ( charArray );
char [] charsFromString = string . toCharArray ();
String zeros = "\ u0000 \ u0000 ";
String s = " stringIsImmutable ";
int length = s. length ();
char firstChar = s. charAt (0);
boolean endsWithTable = s. endsWith (" table ");
boolean containsIs = s. contains ("Is");
String s = " stringIsImmutable ";
String substring = s. substring (0, 6);
String afterReplace = s. replace ("Imm ", "M");
String allCapitals = s. toUpperCase ();
String hello = " Hello ";
String world = " world !";
String helloWorld = hello + world ;
StringBuilder sb = new StringBuilder ();
sb. append ( hello );
sb. append ( world );
String helloWorld = sb. toString ();
boolean referenceEquals = s1 == s2;
boolean contentEquals = s1. equals (s2 );
boolean contentEqualsIgnoreCase =
s1. equalsIgnoreCase (s2 );