logo

Metoda Java StringBuilder append().

The pripni() metoda Jave StringBuilder razred se uporablja za dodajanje vrednosti niza trenutnemu zaporedju. V razredu StringBuilder so na voljo različne preobremenjene metode append(). Te metode se razlikujejo glede na njihove parametre.

Sintaksa:

Oglejmo si drugačno sintakso metode StringBuilder append():

'eulerjevo število v Javi'
 public StringBuilder append(boolean b) public StringBuilder append(char c) public StringBuilder append(char[] str) public StringBuilder append(char[] str, int offset, int len) public StringBuilder append(CharSequence cs) public StringBuilder append(CharSequence cs, int start, int end) public StringBuilder append(double d) public StringBuilder append(float f) public StringBuilder append(int i) public StringBuilder append(long lng) public StringBuilder append(Object obj) public StringBuilder append(String str) public StringBuilder append(StringBuffer sb) public StringBuilder appendCodePoint(int codePoint) 

Parameter:

DataType Parameter Opis
logično b Logična vrednost, ki jo je treba dodati.
char c Vrednost char, ki jo je treba dodati.
char str To so znaki, ki jih je treba dodati.
int odmik Indeks prvega znaka za dodajanje.
int samo Število znakov, ki jih je treba dodati.
CharSequence cs Zaporedje znakov, ki jih želite dodati.
int začetek To je začetni indeks podzaporedja, ki ga je treba dodati.
int konec To je končni indeks podzaporedja, ki ga je treba dodati.
dvojno d Dvojna vrednost, ki jo je treba dodati.
lebdi f Plavajoča vrednost, ki jo je treba dodati.
int jaz Int vrednost, ki jo je treba dodati.
dolga lng Dolga vrednost, ki jo je treba dodati.
Objekt Obj Vrednost predmeta, ki jo je treba dodati.
Vrvica str Vrednost niza, ki jo je treba dodati.
StringBuffer sb StringBuffer, ki je pripet.
int codePoint Int vrednost kodne točke Unicode.

Vrne:

Metoda Vračila
pripni (boolean b) Vrne sklic na ta objekt.
pripni (znak c) Vrne sklic na ta objekt.
pripni(char[] str) Vrne sklic na ta objekt.
dodaj(char[] str, int offset, int len) Vrne sklic na ta objekt.
pripni(CharSequence cs) Vrne sklic na ta Appendable.
dodaj(CharSequence cs, int začetek, int konec) Vrne sklic na ta objekt.
pripni (dvojni d) Vrne sklic na ta objekt.
pripni (float f) Vrne sklic na ta objekt.
pripni(int i) Vrne sklic na ta objekt.
pripni (dolg lng) Vrne sklic na ta objekt.
pripni (obj. predmeta) Vrne sklic na ta objekt.
pripni (niz str) Vrne sklic na ta objekt.
pripni (StringBuffer sb) Vrne sklic na ta objekt.
appendCodePoint(int codePoint) Vrne sklic na ta objekt.

Izjeme:

Metoda Izjema
pripni (boolean b) TO
pripni (znak c) TO
pripni(char[] str) TO
dodaj(char[] str, int offset, int len) IndexOutOfBoundsException
pripni(CharSequence s) TO
append(CharSequence s, int začetek, int konec) IndexOutOfBoundsException
pripni (dvojni d) TO
pripni (float f) TO
pripni(int i) TO
pripni (dolg lng) TO
pripni (obj. predmeta) TO
pripni (niz str) TO
pripni (StringBuffer sb) TO
appendCodePoint(int codePoint) TO

Združljivostna različica:

Java 1.5 in novejši

Primer metode Java StringBuilder append(boolean b).

 public class StringBuilderAppendExample1 { public static void main(String[] args) { StringBuilder sb1 = new StringBuilder('value1 '); System.out.println('builderObject :'+sb1); // appending boolean argument sb1.append(true); // print the StringBuilder after appending System.out.println('after append = ' + sb1); StringBuilder sb2 = new StringBuilder('value2 '); System.out.println('new builderObject :' + sb2); // appending boolean argument sb2.append(false); // print the string Builder after appending System.out.println('after append = ' + sb2); } } 
Preizkusite zdaj

Izhod:

 builderObject :value1 after append = value1 true new builderObject :value2 after append = value2 false 

Primer metode Java StringBuilder append(char c).

 public class StringBuilderAppendExample2 { public static void main(String[] args) { StringBuilder sb1 = new StringBuilder('value1 '); System.out.println('builderObject :'+sb1); // appending char argument sb1.append('A'); // print the StringBuilder after appending System.out.println('after append = ' + sb1); StringBuilder sb2 = new StringBuilder('value2 '); System.out.println('new builderObject :' + sb2); // appending char argument sb2.append('#'); // print the string Builder after appending System.out.println('after append = ' + sb2); } } 
Preizkusite zdaj

Izhod:

mysql ni enako
 builderObject :value1 after append = value1 A new builderObject :value2 after append = value2 # 

Primer metode Java StringBuilder append(char[] str).

 public class StringBuilderAppendExample3 { public static void main(String[] args) { StringBuilder sb1 = new StringBuilder('string '); System.out.println('builderObject :'+sb1); char[] str = {'a','b','c'}; // appending char array argument sb1.append(str); // print the StringBuilder after appending System.out.println('after append = ' + sb1); } } 
Preizkusite zdaj

Izhod:

 builderObject :string after append = string abc 

Primer metode Java StringBuilder append(char[] str, int offset, int len).

 public class StringBuilderAppendExample4 { public static void main(String[] args){ StringBuilder sb1 = new StringBuilder('string builder '); System.out.println('builderObject :'+sb1); char[] str = {'a','b','c','d','e','f','g'}; // appending char array argument sb1.append(str,1,5); // print the StringBuilder after appending System.out.println('after append = ' + sb1); } } 
Preizkusite zdaj

Izhod:

 builderObject :string builder after append = string builder bcdef 

Primer metode Java StringBuilder append(CharSequence cs).

 public class StringBuilderAppendExample5 { public static void main(String[] args) { StringBuilder sb = new StringBuilder('string builder '); System.out.println('builderObject :'+sb); CharSequence cs = 'char sequence'; // appending charsequence argument sb.append(cs); // print the StringBuilder after appending System.out.println('after append = ' + sb); } } 
Preizkusite zdaj

Izhod:

 builderObject :string builder after append = string builder char sequence 

Primer metode Java StringBuilder append(CharSequence cs, int start, int end).

 public class StringBuilderAppendExample6 { public static void main(String[] args) { StringBuilder sb = new StringBuilder('string builder '); System.out.println('builderObject :'+sb); CharSequence cs = 'charsequence'; // appending charsequence argument start at index 4 and end at 8(exclusive) sb.append(cs,4,8); // print the StringBuilder after appending System.out.println('after append = ' + sb); } } 
Preizkusite zdaj

Izhod:

 builderObject :string builder after append = string builder sequ 

Primer metode Java StringBuilder append(double d).

 public class StringBuilderAppendExample7 { public static void main(String[] args) { StringBuilder sb = new StringBuilder('string builder '); System.out.println('builder :'+sb); // appending double argument sb.append(12.6543210123456789d); // print the StringBuilder after appending System.out.println('after append = ' + sb); } } 
Preizkusite zdaj

Izhod:

java izbor sort
 builder :string builder after append = string builder 12.65432101234568 

Primer metode Java StringBuilder append(float f).

 public class StringBuilderAppendExample8 { public static void main(String[] args) { StringBuilder sb = new StringBuilder('string builder '); System.out.println('builder :'+sb); // appending float argument sb.append(10.65f); // print the StringBuilder after appending System.out.println('after append = ' + sb); } } 
Preizkusite zdaj

Izhod:

 builder :string builder after append = string builder 10.65 

Primer metode Java StringBuilder append(int i).

 public class StringBuilderAppendExample9 { public static void main(String[] args) { StringBuilder sb = new StringBuilder('append int '); System.out.println('builder :'+sb); // appending int argument sb.append(100); // print the StringBuilder after appending System.out.println('after append = ' + sb); } } 
Preizkusite zdaj

Izhod:

 builder :append int after append = append int 100 

Primer metode Java StringBuilder append(long lng).

 public class StringBuilderAppendExample10 { public static void main(String[] args) { StringBuilder sb = new StringBuilder('append long '); System.out.println('builder :'+sb); // appending long argument sb.append(9223372036854775807l); // print the StringBuilder after appending System.out.println('after append = ' + sb); } } 
Preizkusite zdaj

Izhod:

 builder :append long after append = append long 9223372036854775807 

Primer metode Java StringBuilder append(Object obj).

 public class StringBuilderAppendExample11 { public static void main(String[] args) { StringBuilder sb = new StringBuilder('append object '); System.out.println('builder :'+sb); Object obj ='objectValue'; // appending object argument sb.append(obj); // print the StringBuilder after appending System.out.println('after append = ' + sb); } } 
Preizkusite zdaj

Izhod:

datoteko za spremembo linuxa
 builder :append object after append = append object objectValue 

Primer metode Java StringBuilder append(String str).

 public class StringBuilderAppendExample12 { public static void main(String[] args) { StringBuilder sb = new StringBuilder('append string '); System.out.println('builder :'+sb); String str ='my string'; // appending string argument sb.append(str); // print the StringBuilder after appending System.out.println('after append = ' + sb); } } 
Preizkusite zdaj

Izhod:

 builder :append string after append = append string my string 

Primer metode Java StringBuilder append(StringBuffer sb).

 public class StringBuilderAppendExample13 { public static void main(String[] args) { StringBuilder stringBuilder = new StringBuilder('append stringBuffer '); System.out.println('builder :'+stringBuilder); StringBuffer sb =new StringBuffer('bufferValue'); // appending string buffer argument stringBuilder.append(sb); // print the StringBuilder after appending System.out.println('after append = ' + stringBuilder); } } 
Preizkusite zdaj

Izhod:

 builder :append stringBuffer after append = append stringBuffer bufferValue 

Primer metode Java StringBuilder appendCodePoint(int codePoint).

 public class StringBuilderAppendExample14 { public static void main(String[] args) { StringBuilder sb1 = new StringBuilder('append codePoint1 '); StringBuilder sb2 = new StringBuilder('append codePoint2 '); // appending codePoint argument sb1.appendCodePoint(64); sb2.appendCodePoint(65); // print the StringBuilder after appending System.out.println('after append :
' +sb1+'
'+sb2); } } 
Preizkusite zdaj

Izhod:

 after append : append codePoint1 @ append codePoint2 A