Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java Examples – Removing a Character from a String

Java Example – Delete a character from a string

Java Examples Java Examples

In the following example we use the string function substring() to remove a character from a string; the functionality is encapsulated in the removeCharAt function.

The example code is as follows:

Main.java File

public

class

Main

{

public

static

void

main

(

String

args

[

]

)

{

String

str

=

"

this is Java

"

;

System

.

out

.

println

(

removeCharAt

(

str

,

3

)

)

;

}

public

static

String

removeCharAt

(

String

s

,

int

pos

)

{

return

s

.

substring

(

0

,

pos

)

s

.

substring

(

pos

1

)

;

}

}

The output of the above code example is:



thi is Java

Java Examples Java Examples