I am currently working on an object-structure exercise where I implement a simple Twitter-interface. I have a TwitterAccount object and a Tweet object. The TwitterAccount object has a Stack that contains all the tweets. In my getTweet(index)-method, I want the newest tweet to be returned with getTweet(1), and second-newest with getTweet(2)... etc.
I do this by creating a temporary tweet-stack, pop index-1 Tweets off the temporary stack, then return the next one. My issue is that the original tweets stack also has it's elements popped. Did I create a pointer to the tweets stack when I created the temporary stack?
Stack<Tweets> tweets;
(...)
public Tweet getTweet(int index) {
Stack<Tweet> tempTweets = tweets;
for (int i = 0; i < index-1; i++)
tempTweets.pop();
return tempTweets.pop();
}