Very simple. Just cast your char
as an int
.
char character = 'a'; int ascii = (int) character;
In your case, you need to get the specific Character from the String first and then cast it.
char character = name.charAt(0); // This gives the character 'a' int ascii = (int) character; // ascii is now 97.
Though cast is not required explicitly, but its improves readability.
int ascii = character; // Even this will do the trick.
Related Posts:
- string to string array conversion in java
- Ignoring upper case and lower case in Java
- How do I print my Java object without getting “SomeType@2f92e0f4”?
- Taking a new line using printf in java? Is %n correct?
- How do I convert a String to an int in Java?
- How to format strings in Java
- Java – Convert integer to string [duplicate]
- What is lexicographical order?
- How to split a string in Java
- How do I compare strings in Java?
- How to convert a char to a String?
- Regex not operator
- How to convert/parse from String to char in java?
- working of \n in python [duplicate]
- Java String Split by “|”
- Regex not operator
- Java string to date conversion
- What is the difference between \r\n, \r, and \n? [duplicate]
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- Regex how to match an optional character
- How to remove punctuation in python?
- Best way to convert an ArrayList to a string
- String variable interpolation Java [duplicate]
- String interpolation in Java 14 or 15
- How do I properly compare strings in C?
- Python: TypeError: cannot concatenate ‘str’ and ‘int’ objects
- How to parse this string in Java?
- How to convert any Object to String?
- How to replace ” \ ” with ” \\ ” in java
- What does strcmp() exactly return in C?
- Illegal Escape Character “\”
- “[ ]” vs. “[[ ]]” in Bash shell
- What does regular expression \\s*,\\s* do?
- How can I remove punctuation from input text in Java?
- How to capitalize the first letter of a String in Java?
- catDog string problem at Codingbat.com
- Return string Input with parse.string
- What is the difference between String.subString() and String.subSequence()
- C – The %x format specifier
- Java compressing Strings
- Lua string.format options
- In Java, how to append a string more efficiently?
- n-grams in python, four, five, six grams?
- Explain the use of a bit vector for determining if all characters are unique
- Convert java.util.Date to String
- Convert array of strings into a string in Java
- Alphabet range in Python
- Detect whether a Python string is a number or a letter
- How to remove single character from a String
- How to remove single character from a String
- What is Java String interning?
- Why is there no String.Empty in Java?
- Java split string to array
- Using Enum values as String literals
- Center text in fixed-width field with stream manipulators in C++
- int cannot be converted to string?
- How to check if my string is equal to null?
- Mips how to store user input string
- what is Ljava.lang.String;@
- bash : Bad Substitution
- Convert String to int array in java
- Converting String Array to an Integer Array
- How to sort an array of objects in Java?
- java.lang.NumberFormatException: empty String
- How to replace a substring of a string
- How to assign multiple lines string in Powershell Console
- Converting A String To Hexadecimal In Java
- Immutable class?
- LC-3 STR with R1 as offset
- Converting a string to an integer on Android
- Simple way to repeat a string
- Java: how to initialize String[]?
- Regular Expressions on Punctuation
- How to extract a substring using regex
- difference between equals() and hashCode()
- How can I process each letter of text using Javascript?
- Java String to SHA1
- PHP to write Tab Characters inside a file?
- Replace a character at a specific index in a string?
- Determine if a String is an Integer in Java [duplicate]
- How can I remove a substring from a given String?
- Java get String CompareTo as a comparator object
- How to use regex in String.contains() method in Java
- How to swap String characters in Java?
- Get an OutputStream into a String
- Difference between string object and string literal
- Passing string to a function in C – with or without pointers?
- Lua String replace
- Trim a string in C [duplicate]
- java: use StringBuilder to insert at the beginning
- C# equivalent to Java’s charAt()?
- Cannot invoke toString() on the primitive type int
- Standard function to replace character or substring in a char array?
- How to compare character ignoring case in primitive types
- Java Not Greater than Or Equal to Operator for Char Type
- Append a single character to a string or char array in java?
- String is immutable. What exactly is the meaning?
- Occurrences of substring in a string
- Fastest way to put contents of Set
to a single String with words separated by a whitespace? - How to know if a given string is substring from another string in Java