Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

convert alphabet to number in java

import java.util.HashMap;
import java.util.Map;


public class JavaApplication1 
{
    public static void main(String[] args) 
    {
        final Map<Character, Integer> map;
        final String str = "hello world";

        map = new HashMap<>();  
        // or map = new HashMap<Character, Integer> if you are using something before Java 7.
        map.put('a', 1);
        map.put('b', 2);
        map.put('c', 3);
        map.put('d', 4);
        map.put('e', 5);
        map.put('f', 6);
        map.put('g', 7);
        map.put('h', 8);
        map.put('i', 9);
        map.put('j', 10);
        map.put('k', 11);
        map.put('l', 12);
        map.put('m', 13);
        map.put('n', 14);
        map.put('o', 15);
        map.put('p', 16);
        map.put('q', 17);
        map.put('r', 18);
        map.put('s', 19);
        map.put('t', 20);
        map.put('u', 21);
        map.put('v', 22);
        map.put('w', 23);
        map.put('x', 24);
        map.put('y', 25);
        map.put('z', 26);

        for(final char c : str.toCharArray())
        {
            final Integer val;

            val = map.get(c);

            if(val == null)
            {   
                // some sort of error
            }
            else
            {
                System.out.print(val + " ");
            }
        }

        System.out.println();
    }
}
Comment

convert alphabet to number in java

import java.util.HashMap;
import java.util.Map;


public class JavaApplication1 
{
    public static void main(String[] args) 
    {
        final Map<Character, Integer> map;
        final String str = "hello world";

        map = new HashMap<>();  
        // or map = new HashMap<Character, Integer> if you are using something before Java 7.
        map.put('a', 1);
        map.put('b', 2);
        map.put('c', 3);
        map.put('d', 4);
        map.put('e', 5);
        map.put('f', 6);
        map.put('g', 7);
        map.put('h', 8);
        map.put('i', 9);
        map.put('j', 10);
        map.put('k', 11);
        map.put('l', 12);
        map.put('m', 13);
        map.put('n', 14);
        map.put('o', 15);
        map.put('p', 16);
        map.put('q', 17);
        map.put('r', 18);
        map.put('s', 19);
        map.put('t', 20);
        map.put('u', 21);
        map.put('v', 22);
        map.put('w', 23);
        map.put('x', 24);
        map.put('y', 25);
        map.put('z', 26);

        for(final char c : str.toCharArray())
        {
            final Integer val;

            val = map.get(c);

            if(val == null)
            {   
                // some sort of error
            }
            else
            {
                System.out.print(val + " ");
            }
        }

        System.out.println();
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: Java Remove Elements from HashSet 
Java :: set web image to imageview android java 
Java :: java multi thread 
Java :: precision java 
Java :: binary search algorithm java 
Java :: java parameterized constructor 
Java :: change color in recyclerview 
Java :: lcm of two number in java 
Java :: java to c# converter 
Java :: login.html 
Java :: data structures in java 
Java :: switch expression java 
Java :: binary tree traversal 
Java :: zoneddatetime java 
Java :: swagger ui java 
Java :: Java Thread Example Using the Thread Class 
Java :: private access modifiers 
Java :: variable might not have been initialized error 
Java :: static method in non static class java 
Java :: java heap example 
Java :: android videoview not smooth for mp4 
Java :: java loop find index 
Java :: exoplayer how to put loader while video is still loading android java 
Java :: from which android version onwards cardelevation supports? 
Java :: Java Using of() Method 
Java :: one space diagonally in java 
Java :: split email on dot java 
Java :: spigot disable health regeneration 
Java :: blast multiple protein files 
Java :: An exception occurred processing JSP page /Home.jsp 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =