Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit441da8a

Browse files
author
rfadatare
committed
string api guide
0 parents  commit441da8a

File tree

158 files changed

+1366
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+1366
-0
lines changed

‎pom.xml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.javaguides.stringhandling</groupId>
4+
<artifactId>java-strings-guide</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
packagecom.javaguides.stringbuffer.methods;
2+
3+
publicclassAppendExample {
4+
publicstaticvoidmain(String[]args) {
5+
// 14 append overloaded methods
6+
7+
// Append String
8+
StringBufferbuffer;
9+
buffer =newStringBuffer().append("guides");
10+
System.out.println("Append String : " +buffer);
11+
12+
// Append char
13+
buffer =newStringBuffer().append('c');
14+
System.out.println("Append char : " +buffer);
15+
16+
// Append Object
17+
buffer =newStringBuffer().append(newObject().getClass());
18+
System.out.println("Append Object : " +buffer);
19+
20+
// Append chars
21+
char[]chars = {'j','a','v','a' };
22+
buffer =newStringBuffer().append(chars);
23+
System.out.println("Append chars : " +buffer);
24+
25+
// Append charSequence
26+
CharSequencecharSequence =newString("charSequence");
27+
buffer =newStringBuffer().append(charSequence);
28+
System.out.println("Append charSequence : " +buffer);
29+
30+
// Append Double
31+
buffer =newStringBuffer().append(10.0d);
32+
System.out.println("Append Double : " +buffer);
33+
34+
// Append Float
35+
buffer =newStringBuffer().append(10.5f);
36+
System.out.println("Append Float : " +buffer);
37+
38+
// Append int
39+
buffer =newStringBuffer().append(100);
40+
System.out.println("Append int : " +buffer);
41+
42+
// Append Boolean
43+
buffer =newStringBuffer().append(true);
44+
System.out.println("Append Boolean : " +buffer);
45+
46+
// Append Long
47+
buffer =newStringBuffer().append(1000);
48+
System.out.println("Append Long : " +buffer);
49+
50+
// Append stringbuffer
51+
buffer =newStringBuffer().append(newStringBuffer("stringbuffer"));
52+
System.out.println("Append stringbuffer : " +buffer);
53+
54+
// Appends the string representation of a subarray of the char array
55+
// argument to this sequence.
56+
buffer =newStringBuffer().append(chars,1,3);
57+
System.out.println("Appends the string representation of a "
58+
+" subarray of the char array argument to this sequence. : " +buffer);
59+
60+
// Appends a subsequence of the specified CharSequence to this sequence
61+
buffer =newStringBuffer().append("javaguides",0,9);
62+
System.out.println("Appends a subsequence of the specified "
63+
+" CharSequence to this sequence. : " +buffer);
64+
65+
// Appends the string representation of the codePoint argument to this
66+
// sequence.
67+
buffer =newStringBuffer().appendCodePoint(5);
68+
System.out.println(
69+
"Appends the string representation of the "
70+
+" codePoint argument to this sequence. : " +buffer);
71+
}
72+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
packagecom.javaguides.stringbuffer.methods;
2+
3+
publicclassCapacityExample {
4+
publicstaticvoidmain(String[]args) {
5+
StringBufferbuilder =newStringBuffer("javaguides");
6+
intcapacity =builder.capacity();
7+
8+
// inital capacity
9+
System.out.println(newStringBuffer().capacity());
10+
11+
// intial capacity 16 + number of characters in string
12+
System.out.println("Capacity of the string :: " +capacity);
13+
}
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
packagecom.javaguides.stringbuffer.methods;
2+
3+
publicclassChatAtExample {
4+
publicstaticvoidmain(String[]args) {
5+
charAtExample1();
6+
//charAtExample2();
7+
charAtExample3();
8+
}
9+
10+
publicstaticvoidcharAtExample1() {
11+
StringBufferbuffer =newStringBuffer("Welcome to string handling guide");
12+
charch1 =buffer.charAt(0);
13+
charch2 =buffer.charAt(5);
14+
charch3 =buffer.charAt(11);
15+
charch4 =buffer.charAt(20);
16+
System.out.println("Character at 0 index is: " +ch1);
17+
System.out.println("Character at 5th index is: " +ch2);
18+
System.out.println("Character at 11th index is: " +ch3);
19+
System.out.println("Character at 20th index is: " +ch4);
20+
}
21+
22+
// IndexOutOfBoundsException - if the index argument is negative or not less
23+
// than the length of this string.
24+
publicstaticvoidcharAtExample2() {
25+
StringBufferbuilder =newStringBuffer("Java Guides");
26+
charch1 =builder.charAt(builder.length());
27+
System.out.println("character :: " +ch1);
28+
}
29+
30+
// How to get first and last chanracter of the string
31+
publicstaticvoidcharAtExample3() {
32+
StringBufferbuffer =newStringBuffer("Java Guides");
33+
intstrLength =buffer.length() -1;
34+
// Fetching first character
35+
System.out.println("Character at 0 index is: " +buffer.charAt(0));
36+
// The last Character is present at the string length-1 index
37+
System.out.println("Character at last index is: " +buffer.charAt(strLength));
38+
}
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
packagecom.javaguides.stringbuffer.methods;
2+
3+
publicclassCodePointAtExample {
4+
publicstaticvoidmain(String[]args) {
5+
StringBufferbuffer =newStringBuffer("javaguides");
6+
intunicode =buffer.codePointAt(0);
7+
System.out.println("the character (Unicode code point) at the specified index is :: " +unicode);
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
packagecom.javaguides.stringbuffer.methods;
2+
3+
publicclassCodePointBeforeExample {
4+
publicstaticvoidmain(String[]args) {
5+
StringBufferbuffer =newStringBuffer("javaguides");
6+
intunicode =buffer.codePointBefore(1);
7+
System.out.println("the character (Unicode code point) at the before specified index is :: " +unicode);
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
packagecom.javaguides.stringbuffer.methods;
2+
3+
publicclassCodePointCountExample {
4+
publicstaticvoidmain(String[]args) {
5+
StringBufferbuffer =newStringBuffer("javaguides");
6+
System.out.println("length of the string :: " +buffer.length());
7+
intunicode =buffer.codePointCount(0,buffer.length());
8+
System.out.println("the character (Unicode code point) at the specified index is :: " +unicode);
9+
}
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
packagecom.javaguides.stringbuffer.methods;
2+
3+
publicclassDeleteExample {
4+
publicstaticvoidmain(String[]args) {
5+
StringBufferbuffer =newStringBuffer("javaguides");
6+
7+
// start with index and end with end -1
8+
StringBuffersubBuffer =buffer.delete(0,4);
9+
System.out.println("Delete string 'java' from string 'javaguides' : " +subBuffer.toString());
10+
11+
StringBuffersubBuilder1 =newStringBuffer("javaguides").deleteCharAt(4);
12+
System.out.println("Delete char 'g' from string 'javaguides' : " +subBuilder1);
13+
}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
packagecom.javaguides.stringbuffer.methods;
2+
3+
publicclassEnsureCapacityExample {
4+
publicstaticvoidmain(String[]args) {
5+
StringBufferbuilder =newStringBuffer();
6+
builder.ensureCapacity(11);
7+
System.out.println(builder.capacity());
8+
builder.ensureCapacity(17);
9+
System.out.println(builder.capacity());
10+
}
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
packagecom.javaguides.stringbuffer.methods;
2+
3+
publicclassGetCharsExample {
4+
publicstaticvoidmain(String[]args) {
5+
StringBufferbuffer =newStringBuffer("javaguides");
6+
char[]dst =newchar[buffer.length()];
7+
buffer.getChars(0,buffer.length(),dst,0);
8+
9+
for (charc :dst) {
10+
System.out.println(c);
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp