Chapter 11: Strings


JDK 7u6 dan pastki qator usuli har doim barcha asosiy [] massivni nusxalaydi, bu murakkablikni oldingi doimiyga nisbatan chiziqli qiladi, lekin bir vaqtning o'zida xotira oqishining yo'qligini kafolat


Download 0.83 Mb.
bet10/12
Sana18.12.2022
Hajmi0.83 Mb.
#1031312
1   ...   4   5   6   7   8   9   10   11   12
Bog'liq
dasturlsh string

JDK 7u6 dan pastki qator usuli har doim barcha asosiy [] massivni nusxalaydi, bu murakkablikni oldingi doimiyga nisbatan chiziqli qiladi, lekin bir vaqtning o'zida xotira oqishining yo'qligini kafolatlaydi.



Section 11.9: Platform independent new line separator


Yangi chiziq ajratgich platformadan platformaga farq qilganligi sababli (masalan, Unix-ga o'xshash tizimlarda \n yoki Windowsda \r\n) unga kirishning platformadan mustaqil usuli bo'lishi kerak. Java-da uni tizim xususiyatidan olish mumkin:

Version ≥ Java SE 7
Yangi chiziq ajratgich juda tez-tez talab qilinganligi sababli, Java 7-dan yuqoridagi kod bilan bir xil natijani qaytaruvchi yorliq usulida mavjud:
Yangi chiziq ajratgich juda tez-tez talab qilinganligi sababli, Java 7-dan yuqoridagi kod bilan bir xil natijani qaytaruvchi yorliq usulida mavjud:

System.out.println(String.format('line 1: %s.%nline 2: %s%n', lines[0],lines[1]));

Section 11.10: Reversing Strings


  1. Stringni orqaga qaytarish uchun bir nechta usul mavjud.

  2. StringBuilder/StringBuffer:



  1. Char array:


Section 11.11: Adding toString() method for custom objects



Agar siz yangi Person ob'ektini yaratsangiz:
va keyinchalik kodingizda ob'ektni chop etish uchun quyidagi bayonotdan foydalanasiz:

Live Demo on Ideone you'll get an output similar to the following:


toString
Bu ob'ekt sinfida aniqlangan () usulini amalga oshirish natijasidir, yuqori sinf
Ob'ekt. toString
Shaxs. () hujjatida quyidagilar aytiladi:

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())

toString

Shunday qilib, mazmunli chiqish uchun siz () usulini bekor qilishingiz kerak bo'ladi:


Now the output will be:

You can also write

Live Demo on Ideone

println

Download 0.83 Mb.

Do'stlaringiz bilan baham:
1   ...   4   5   6   7   8   9   10   11   12




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling