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.

public static LinkedList MuRikr = new LinkedList();
     public static int votes=0; 
     public static String[] Results;

     // further on...
     votes = (MuRikr.size());//Returns the number of elements in this list.
     //Str2 is a String
     Results += (votes + " : " + Str2);//line 80, incompatiable types

Your help is very much appreciated. Thanks sooo much!!

7 Years
Discussion Span
Last Post by mmusehani

Results is an array, and you can't append to an array with +=, that just works for numbers and simple Strings.
You need to keep track of how many elements of the array you have already used so that you can put the new String into the next available empty element in the array (or maybe you are in a loop that has an integer loop control variable that you can use as an index).

Edited by JamesCherrill: n/a


You can also use java.util.Vector if you don't know how big your array should be.

Vector result = new Vector();
result.add([your object]);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.