Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to continously key in elements of a String[ ]

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic