Skip to content

Commit

Permalink
6.3. Промежуточные операции. Метод mapToObj(). Стрим из символов строки
Browse files Browse the repository at this point in the history
  • Loading branch information
devvk committed Oct 23, 2024
1 parent 17c92e3 commit 95a9f45
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/ru/job4j/stream/CharsMethod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.job4j.stream;

import java.util.List;

public class CharsMethod {
public static List<Character> symbols(String string) {
return string.chars()
.mapToObj(i -> (char) i)
.toList();
}
}
17 changes: 17 additions & 0 deletions src/test/java/ru/job4j/stream/CharsMethodTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ru.job4j.stream;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class CharsMethodTest {

@Test
public void test() {
String input = "123";
List<Character> expect = List.of('1', '2', '3');
assertEquals(expect, CharsMethod.symbols(input));
}
}

0 comments on commit 95a9f45

Please sign in to comment.