# How do i put multiple charAt's in one char?

• 11-03-2012, 12:00 AM
How do i put multiple charAt's in one char?
char threeMorse = myMorse[2].charAt(0);

this works, it returns the char at the 0 spot of this array spot which return 3

What if I want to do something like char threeMorse = myMorse[2].charAt(0) + myMorse[2].charAt(1); <------This doesnt work but I want something similar to this logic

Is this possible? Thanks
• 11-03-2012, 12:03 AM
Fubarable
Re: How do i put multiple charAt's in one char?
Perhaps you should explain what you're trying to do in general terms, not in coding terms. What do you want to achieve with this code?
• 11-03-2012, 12:04 AM
Re: How do i put multiple charAt's in one char?
I want to put the first two spots of an arrays data into one char
• 11-03-2012, 12:04 AM
Re: How do i put multiple charAt's in one char?
It has some extra useless data after it that I dont need so I just want the first 2 spots
• 11-03-2012, 12:10 AM
Fubarable
Re: How do i put multiple charAt's in one char?
Quote:

I want to put the first two spots of an arrays data into one char

I don't understand this. It almost seems that you're trying to wedge two char into one char, and that obviously can't be done. Again, please tell me what problem this part of your program is trying to solve, rather than how you're trying to solve it with code.
• 11-03-2012, 12:19 AM
Re: How do i put multiple charAt's in one char?
Ah yeah I guess thats not possible with a char but anyways

I read a morse code from a text and I need the user to input a number or letter, and the program needs to spit the morse code equivalent back out at the user. I already stored the data from the morse txt into an array. THe problem is the morse .txt is listed with a number or letter in front of it. SO S in the morse txt looks like:
'S ---'
When the user asks for S I need the program to return --- and not S ---. I'm so close to getting it finished I need to figure out how to take off the first 2 parts of the data in each array slot whenever they ask for it you know?
• 11-03-2012, 12:20 AM
Re: How do i put multiple charAt's in one char?
How can I add charAt's? How do I concatenate them
• 11-03-2012, 12:27 AM
Fubarable
Re: How do i put multiple charAt's in one char?
It sounds like what you want to use is a Map, perhaps a HashMap<Character, String> so you can associate the char 's' with the String "---". If you have this and load it with all the char and dot-dash Strings that represent Morse code, then you can get the Morse String that corresponds with the 's' character by doing

String morseString = myMap.get('s');
• 11-03-2012, 12:37 AM
Re: How do i put multiple charAt's in one char?
That sounds confusing I never used maps
• 11-03-2012, 12:42 AM
Fubarable
Re: How do i put multiple charAt's in one char?
They're not that hard once you get used to using them. Say for instance you created a map to translate Spanish words to English:

Code:

`HashMap<String, String> spanishToEnglishMap = new HashMap<String, String>();`
You could fill it like so:

Code:

```spanishToEnglishMap.put("hola", "hello"); spanishToEnglishMap.put("adiós", "goodbye"); spanishToEnglishMap.put("muchacho", "boy"); spanishToEnglishMap.put("muchacha", "girl"); spanishToEnglishMap.put("mujer", "woman"); spanishToEnglishMap.put("hombre", "man");```
and then use it like so:

Code:

```String text = "The English word for mujer is " + spanishToEnglishMap.get("mujer"); System.out.println(text);```
• 11-03-2012, 12:47 AM