Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

OPI_LR2011_ch3

.pdf
Скачиваний:
5
Добавлен:
07.02.2016
Размер:
1.31 Mб
Скачать

71

(byte)0x3,(byte)0x9,(byte)0xDl

};

char[] c = {'1', '2', '9', '9', '/', '5'}; String s1 = new String(c);

String s2 = new String(byteCp866); // ?g5 P2792g8 MS Windows String s3 = "1299/5";

System.out.println();

try{

// •2@862RgO775 @ Cp866 6g5 @/@26N 7= P2792g; MS Windows. msg = new String("\"12985\" @ ".getBytes("Cp866"), "Cpl251"); winLikeWin = new String(byteCp1251, "Cpl251"); //•4=@/g;72 winLikeDOS = new String(byteCpl251,: "Cp866");

winLikeUNIX - new String(byteCp1251, "KOI8-R");

dosLikeWin = new String(byteCp866, "Cpl251"); // ?g5 P2792g8 dosLikeDOS = new String(byteCp866, "Cp866"); // •4=@/g;72 dosLikeUNIX = new String(byteCp866, "KOI8-R");

unixLikeWin = new String(byteKOISR, "Cpl251"); unixLikeDOS = new String(byteKOISR, "Cp866");

unixLikeUNIX = new String(byteKOISR, "KOI8-R"); // •4=@/g;72 System.out.print(msg + "Cpl251: "); System.out.write(byteCp1251);

System.out.println(); System.out.print(msg + "Cp866: "); System, out.write(byteCp866} ; System.out.println(); System.out.print(msg + "KOI8-R: "); System.out.write(byteKOI8R);

{catch(Exception e)( e.printStackTrace();

}

System.out.println();

System.out.println();

System.out.println(msg + "char array : " + s1); System.out.println(msg + "default encoding: " + s2); System.out.println(msg + "string constant : " + s3); System.out.println();

System.out.println(msg + "Cp1251 -> Cp1251: " + winLikeWin); System.out.println(msg + "Cp1251 -> Cp866: " + winLikeDOS); System.out.println(msg + "Cp1251 -> KOI8-R: " + winLikeUNIX); System.out.println(msg + "Cp866 -> Cp1251: " + dosLikeWin); System.out.println(msg + "Cp866 -> Cp866: " + dosLikeDOS); System.out.println(msg + "Cp866 -> KOI8-R: " + dosLikeUNIX); System.out.println(msg + "KOI8-R -> Cpl251: " + unixLikeWin); System.out.println(msg + "KOI8-R -> Cp866: " + unixLikeDOS); System.out.println(msg + "KOI8-R -> KOI8-R: " + unixLikeUNIX);

}

}

? MS Windows 2000,

. 6.1.

72

g

byteCP1251, byteCP866 byteKOI8R Unicode. D

f write() FilterOutputStream java.io.

Java,

c[], byteCP866 - . : .

= 6.1 – ? MS Windows

Command Prompt MS Windows >=866.

E i , "="

, i >=866,

msg.

. 5.1

+ codes.txt. ? MS Windows 2000

+ f >=1251.

-( 7( ) )91,"

( @

(concatenation), f «+». D

@f , g

73

. ž ( ,

. ::

String attention = "s@=\=: ";

String s = attention + "7O@862R/> 9/R@2g";

E - @ += - f

:

attention += s;

, 7);,< )91 !4

E i ( ,

, length():

String s = "Write once, run anywhere."; int len = s.length{);

i g

int len = "Write once, run anywhere.".length();

- - 'f string. ', i - , f length.

? ind( g

@f @) ( charAt(int ind) G i ind

'f g ( ( , f

. :,

char ch = s.charAt(3);

ch 't'

? ( (

toCharArray(); // j2 02@O4:=b R=9/@ 9/R@2g8@.

G i ( @ dst, @

ind begin @ end

, getChars(int begin, int end, char[] dst, int ind) void.

end - begin ,

, @ ind in d +(end - begin) - 1.

G i ( , i

ASCII,

getBytes().

substring(int begin, int end) f

begin @ end @. E ( @f end - begin.

substring(int begin) f begin

@ .

74

G i 'f, end g (

begin g end, f . :,

String s = "Write on9e, run anywhere."; String sub1 = s.substring(6, 10); String sub2 = s.substring(16);

( sub1 " once ", sub2 - " anywhere ".

. == @f . ? 'f, @ . :,

String s1 = "lP/>9; 4562P";

String s2 = "•7f/> 4562P";

s1 == s2 f false.

true , i @

, , @ s1 = s2. D, i i s2 :

String s2 == "lP/>9; 4562P";

s1 == s2 true, i

"G "

.

e equals(object obj),

object, f true, i obj @f null, f 'f

string, @ (

. ? g f false.

e equalsIgnoreCase(object obj) @f ,

, , ( @

@.

compareTo(string str) f int,

:

= @ this str

, , k,

.

g f this.charAt(k) - str.charAt(k), Unicode g (

. f this.length() - str.length(), ( . G i @,

f 0. G i str @f null, f

. : f ( , equals()

f true.

75

compareToIgnoreCase(string str)

, g (, f

this.toUpperCase().toLowerCase().compareTo( str.toUpperCase().toLowerCase());

- compareTo(Object obj) @f

@, i obj f . ? g @f

compareTo(String str).

D @ + g

.

this @ f (

( len g str (

regionMatches(int ind1, String str, int ind2, int len)

; ind1 - this, ind2 -

g str. = false

:

ind1 ind2 'f;

ind1 + len ind2 + len g (

;

f.

D f , . G i

@ ,

:

regionMatches(boolean flag, int ind1, String str, int ind2, int len)

G i g flag @f true,

f, i false - f. ' g ( .

' g ch this ( (

indexOf(int ch), i f

-1, i ch this f.

:, " ", indexOf(' ') 1.

, f

this.charAt(k++> == ch), ( true.

E ch this (

( indexOf(int ch, int ind).

D f g ch ind. G i ind < 0, g , i ind g ( ,

g f, f -1.

:, " ".indexof(' ', indexof(' ') + 1)

3.

76

. ch this f

lastIndexOf(int ch). ? f . G i ch , f.-1.

:, " ".lastindexof(' ') 5. ' ch

this ( ( lastIndexof(int ch, int ind), i

f , @ ind. G i ind g ( , g ,

i ind < 0, f-1.

' g ( sub this g f

indexof(String sub). ? f g

g ( sub -1, i sub

this. :, "= +".indexof(" ")

4.

. f ( sub this (

g lastIndexOf(string sub), i f

g ( sub this

(-1), i sub this.

. f ( sub this,

ind ( g lastIndexof(String stf, int ind). G i ind g ( , g

, i ind < 0, f -1.

E i , f this

sub, startsWith(string sub), i f true, i this f

sub, f @, sub (.

( sub this,

@ ind startsWith(String sub, int ind). G i ind g ( ,

f false.

E i , f this

sub,

endsWith(String sub). ? f true, i sub f

sub (.

:, if(fileName.endsWith(".Java")) (

+ Java.

' i @@ @, i

sub == null.

77

G i g, i f ,

.

, ( @

toLowerCase(Locale loc) toUpperCase(Locale loc).

replace(int old, int new) f ,

( old new. G i old

f, f . :, "= f ", replace(' ',

' ') ( " = f ". = f.

trim() f ,

, i i @ '\u0020'.

C string valueOf(type elem)

boolean, char, int, long, float, double, char[], 'f object.

E' valueof(char[] ch, int offset, int len)

ch, i f offset f len

.

6.3 "9 ) 9 4

6.3.1.

@ , @ , (

.

6.3.2? Java .

6.3.3? :

:

1.? +( -

) @ .

2.? ( @

( int) g (16-

( )

3.: 2 +

( (toUpperCase, toLowerCase);

+ @, i f ,

f f (

( @ ).

78

0 :

1.? n ,

. ? @ (.

2.? n .

( ) (.

3.? n . ? ,

( g (g) , (

(.

4.? n . ,

. G i ,

g .

5.? n . , i

+, -

.

6.? n . ,

. G i

, g .

7.? n . , i f

. G i ,

g .

8.? n . > , i @

+, - . G i

g , .

9.? @ switch, , i

(

k (-10k, 5], [0, 10], [5, 15], [10, 10k].

10.? 1 12. ?

, i f . (

).

6.3.4.+ .

6.3.5? .

6.4 !, #",

6.4.1; .

6.4.2.

79

6.4.3C .

6.4.4; .

6.4.5= .

6.4.6?, i

(5 g. ), ( ( @

.

6.5 7] , # 4 )

6.5.1: Java.

6.5.2E String?

6.5.3: String?

6.5.4. String?

6.5.5G Java ?

f?

6.5.6G Java?

6.5.7E StringBuffer?

6.5.8G StringBuffer ? f?

6.5.9String StringBuffer?

6.5.10G ,

Java ? f?

80

7 ? 8 8 8 ? 7

-C h

7.1( 4

: -

Java.

7.2" , ( ( 4-, ",9 ! ,

7.2.1 7 Vector

Java g f vector,

object.

C vector java.util f object,

- . C ( -@

. ” ( @ 0, 1, 2,.... E ( ( ,

.

C , (size) , f i

+ f (capacity) . f f

, ( g ensureCapacity(int minCapacity) trimToSize().

:

vector();

Vector(int capacity);

vector(int capacity, int increment); vector(Collection 9);

add(Object element) f

( ( addElement(Object element).

add(int index, Object element)

insertElementAt(Object element, int index) (

index. addAll(Collection coll) f

coll. addAll(int index, Collection coll) ( @ index

coll. set(int index, object element) f , i

index, element. C

( ( size().

capacity() f f .

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]