push a string into an array
in
Programming Questions
•
1 year ago
how would do the equivalent in Java as array.push(string); in java? I can't seem to get it to work correct, some research lead me to
ArrayList but I can't find any good references that explain it well.
Trying to play around with a twitter example and actually render the text, here is what I have so far:
- PFont f;
- ArrayList al = new ArrayList();
- void setup() {
- size(780, 600);
- f = createFont("Arial", 16, true); // STEP 3 Create Font
- ConfigurationBuilder cb = new ConfigurationBuilder();
- // replaced actual values with ****
- cb.setOAuthConsumerKey("****");
- cb.setOAuthConsumerSecret("****");
- cb.setOAuthAccessToken("****-****");
- cb.setOAuthAccessTokenSecret("****");
- Twitter twitter = new TwitterFactory(cb.build()).getInstance();
- Query query = new Query("#keyword");
- query.setRpp(100);
- try {
- QueryResult result = twitter.search(query);
- ArrayList tweets = (ArrayList) result.getTweets();
- for (int i = 0; i < tweets.size(); i++) {
- Tweet t = (Tweet) tweets.get(i);
- String user = t.getFromUser();
- String msg = t.getText();
- Date d = t.getCreatedAt();
- println("Tweet by " + user + " at " + d + ": " + msg);
- al.add(msg);
- };
- }
- catch (TwitterException te) {
- println("Couldn't connect: " + te);
- };
- }
- void draw() {
- background(255);
- textFont(f, 16);
- fill(0);
- for(String msg : al){ // this is shorthand... I think?
- // also tried: for(int i = 0; i < al.length; i++){
- // which gave me error that al.length cannot be resolved or is not a value
- text(al[i], 10, i+20);
- }
- }
I can definitely get it to get the messages from twitter, but I get this error: cannot convert from element type Object to string
1