Skip to content

Latest commit

 

History

History
24 lines (19 loc) · 553 Bytes

string-to-ascii.md

File metadata and controls

24 lines (19 loc) · 553 Bytes
title description author tags
String To Ascii
Converts a string into ascii numbers
Mcbencrafter
string,ascii,encoding,conversion
import java.util.ArrayList;
import java.util.List;

public static List<Integer> stringToAscii(String text) {
    List<Integer> asciiCodes = new ArrayList<>();

    for (char character : text.toCharArray()) {
        asciiCodes.add((int) character);
    }

    return asciiCodes;
}

// Usage:
System.out.println(stringToAscii("hello world")); // [104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]