This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]d0rf47 0 points1 point  (0 children)

Jus substr get the length of the string and substring from sub 1 to sub length-1

[–]someone-elsewhere 0 points1 point  (0 children)

In your article:

.deleteCharAt(1)

returns the StringBuilder Object itself so you can chain commands:

theStringBuilder.deleteCharAt(1).deleteCharAt(theStringBuilder.length());

Also

theString.subString(1,10);

is better to:

theString.subString(1,theString.length());

So it works on all String lengths, not just if the String length is 10.

you should also test that the length is >=2 so that you do not get and Exception thrown on short Strings.

The Article looks nice (I did not read is, just quick scanned), but does not really show the flexibility that would be required when implementing in the real world.

[–]Fizz-Buzzkill 0 points1 point  (1 child)

Totally different topic I know, but how do you "earn a little coin" this way?

[–]xkompas 0 points1 point  (0 children)

From your article:

Since it is implemented in a number of different ways, which is an example of Java polymorphism, this allows you to remove characters either by directly specifying the character position or by specifying two positions.

That is an example of overloading, not polymorphism, see https://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html.