# Can we have something like myintarray[a] = 0 where "a" is a string value??

• January 23rd, 2012, 09:13 AM
NickNickk
Can we have something like myintarray[a] = 0 where "a" is a string value??
Say if we have String s = "abcdefg"

is it possible to do something like this

myArray[a] = 0
myArray[b] = 1
myArray[c] = 2
myArray[d] = 3
myArray[e] = 4
.
.
.

where a,b,c,d,e ... are string values

Many Thanks
• January 23rd, 2012, 09:39 AM
newbie
Re: Can we have something like myintarray[a] = 0 where "a" is a string value??
No it isn't possible, as the values are integer pointers to data.
You could however do myIntArray[Integer.valueOf("23")] = 2; if you so desired.
• January 23rd, 2012, 09:50 AM
KevinWorkman
Re: Can we have something like myintarray[a] = 0 where "a" is a string value??
Quote:

Originally Posted by NickNickk
Say if we have String s = "abcdefg"

is it possible to do something like this

myArray[a] = 0
myArray[b] = 1
myArray[c] = 2
myArray[d] = 3
myArray[e] = 4
.
.
.

where a,b,c,d,e ... are string values

Many Thanks

What does the String s have to do with the rest of your question? Do you want the array indices to equal the index of the character? If so, String has methods to do just that. The API is your friend.
• January 23rd, 2012, 11:21 AM
Norm
Re: Can we have something like myintarray[a] = 0 where "a" is a string value??
Sounds like you want to use a Map. The String would be the key to get a value from the Map.
value = theMap.get("a String");