Skip to content

Commit b5bafd1

Browse files
authored
KTLN-453: Convert String to Char in Kotlin (#803)
* pom kotlin version * pom version * Added unit tests
1 parent cba3c35 commit b5bafd1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.baeldung.stringToChar
2+
3+
import org.junit.jupiter.api.Assertions.assertEquals
4+
import org.junit.jupiter.api.Test
5+
6+
class StringToCharUnitTest {
7+
8+
@Test
9+
fun `converts string to char using get method`(){
10+
val str = "H"
11+
val char = str.get(0)
12+
13+
assertEquals('H', char)
14+
}
15+
16+
@Test
17+
fun `converts string to char using index operator method`(){
18+
val str = "H"
19+
val char = str[0]
20+
21+
assertEquals('H', char)
22+
}
23+
24+
@Test
25+
fun `converts string to char using single method`(){
26+
val str = "H"
27+
val char = str.single()
28+
29+
assertEquals('H', char)
30+
}
31+
32+
@Test
33+
fun `converts string to char using first method`(){
34+
val str = "H"
35+
val char = str.first()
36+
37+
assertEquals('H', char)
38+
}
39+
40+
@Test
41+
fun `converts string to char using toCharArray method`(){
42+
val str = "H"
43+
val charArray = str.toCharArray()
44+
val char = charArray[0]
45+
46+
assertEquals('H', char)
47+
}
48+
}

0 commit comments

Comments
 (0)