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

1. Member
Join Date
Nov 2012
Posts
12
Rep Power
0

## 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

2. ## 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?

3. Member
Join Date
Nov 2012
Posts
12
Rep Power
0

## 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

4. Member
Join Date
Nov 2012
Posts
12
Rep Power
0

## 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

5. ## Re: How do i put multiple charAt's in one char?

Originally Posted by maskanio
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.

6. Member
Join Date
Nov 2012
Posts
12
Rep Power
0

## 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?

7. Member
Join Date
Nov 2012
Posts
12
Rep Power
0

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

How can I add charAt's? How do I concatenate them

8. ## 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');

9. Member
Join Date
Nov 2012
Posts
12
Rep Power
0

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

That sounds confusing I never used maps

10. ## 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:

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

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

Java Code:
```String text = "The English word for mujer is " + spanishToEnglishMap.get("mujer");
System.out.println(text);```

11. Member
Join Date
Nov 2012
Posts
12
Rep Power
0

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

Do I have to declare hashmap as a string or something?

12. Member
Join Date
Nov 2012
Posts
12
Rep Power
0

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

Ah it worked man ty!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•