Cannot convert from Object array to String array
in
Programming Questions
•
3 months ago
Hi
I implemented arrayList to store Strings down the code. I didn't know the size so instead pure Array I implemented the list. I was looking for the way to convert objects from the arrayList to Strings and found
how convert the Object to String. At the line 34 PApplet gives me a message "cannot convert from Object[] to String[].
I'm trying sort out the words from XML feed and analyze vocabulary. Could you please help me with arrayList converting.
- XML xml;
- String[] news = new String[10]; // <<< initiate global arrayList instead
- ArrayList wrd = new ArrayList<String>();
- int[] reps = new int[1000]; // nubmers 10 (the number of news) and 1000 (the number of words)
- int index = 0;
- String exceptionWords = "-,of,the";
- String[] junctions = split(exceptionWords, ",");
- void setup() {
- xml = loadXML("http://www.reuters.com/rssFeed/topNews"); // Adress of XML
- XML channel = xml.getChild("channel"); // Getting into the channel of the XML
- XML[] items = channel.getChildren("item/description"); // Gets into item and then in item gets into description
- //String[] news;
- for (int i = 0; i < items.length; i++) { // iterate through all elements "description"
- //println(items[i].getContent()); // Prints the content of the element "description"
- news[i]=(items[i].getContent()); // Record news into the GLOBAL String array
- }
- //println(news);
- String words = join(news, ' '); // Join all elements of the array "news" into a single String
- String[] wordsArray = split(words, " "); // Create array of words from the text "news"
- for (int i = 0; i < wordsArray.length; i++) {
- for (int j = 0; j < junctions.length; j++) {
- if (wordsArray[i] != junctions[j]) {
- wrd.add((String)wordsArray[i]);
- index++;
- println(index);
- } else {
- }
- }
- }
- String[] wordsCopy = wrd.toArray(new String[wrd.size()]);
- //println(junctions);
- for (int i = 0; i < wrd.length; i++) { // For loop to get item from wordsArray for comparisson
- for (int j = 0; j < wordsCopy.length; j++) { // For loop to run through every word in wordsCopy comparing the singel element from wordsArray
- if (wrd[i].equals(wordsCopy[j]) == true) {
- reps[i] = reps[i] + 1;
- }
- }
- println(wordsArray[i] + " " + reps[i] + " times ");
- }
- //println(wordsArray);
- }
1