We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I have an array of strings that looks like, {"a","b","d","c","c","e","f","c"}
How can I create an Integer array that can list all the index values of the String array member, c (like {3,4,7})?
It would be great if someone can help me with this! Many thanks in Advance :)
Answers
well, you need one array for each character / String, right?
Look at hashMap please
it's one hashMap for all characters / Strings
I think you could use the String "c" e.g. as the input and the Array {3,4,7} as output of the hashMap (at the position "c" in the hashmap)
new version with a display of a small table
Thank you @Chrisir :) I have to spend sometime to get a grip on the basics of HashMap
I was trying to work with the hashMap after your first comment.
Over here, I was able to print the index numbers in the console. is there an easy way to 'clean' them and take out as an array of integers ? (sorry for my less programming proficiency:D )
you wrote:
No, you still need one array for each letter
you could make a 2D array - see tutorials
what's wrong with my solution?
There is nothing wrong with with your Solution @ Chrisir. As a beginner, I was trying out other ways. Your solution works well :)
Thanks again :)
I see
now, you wrote:
I did that with append. That would work
but you then still need one array per char or a 2D array
better readable version
This is great!! thanks a lot @chrisir and @GoToLoop :)
you're welcome!