• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to continously key in elements of a String[ ]

 
Jerri Loh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there,

Here's a snippet of my code.

1)I am trying to assign the value "(votes + " : " + Str2)" as an element of the String[] Results at the end of my for loop. So at the end of every loop, there is a new entry made to String[] Results.
I am not sure whether it has gotta do with contenating.

2)line 80 compilation error states having incompatible types.
I have tried explicit casting to String, but it does not help. I am aware that variable "votes" is an integer and Str 2 is a String. But I would want to store "(votes + " : " + Str2)" as a String, as an element of String[] Results.




Your help is very much appreciated. Thanks sooo much!!
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you can't assign a String to a String array. That doesn't work.

An array has an index in which you put the values.
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+ is only applicable to numeric primitives (and because of auto-unboxing, also numeric wrapper types) and Strings, not String arrays. You may want to switch from a String[] to a List<String> so you can use the add method.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have moved this topic to Beginning Java.
 
Jerri Loh
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my greatest gratitude to the 3 wise men on Java ranch. aites. getting down to Rob prime's suggestion! Thanks Sebestian! And wouter oet is always re-categorising my posts.. sorry for the trouble! :S
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic