GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes  How to continously key in elements of a String[ ] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark " How to continously key in elements of a String[ ]" Watch " How to continously key in elements of a String[ ]" New topic
Author

How to continously key in elements of a String[ ]

Jerri Loh
Ranch Hand

Joined: Jul 06, 2010
Posts: 31
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

Joined: Feb 23, 2009
Posts: 1183
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.


JDBCSupport - An easy to use, light-weight JDBC framework -
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

+ 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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

I have moved this topic to Beginning Java.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Jerri Loh
Ranch Hand

Joined: Jul 06, 2010
Posts: 31
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
 
 
subject: How to continously key in elements of a String[ ]