• Post Reply Bookmark Topic Watch Topic
  • New Topic

non empty arraylist returns true for isEmpty()  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println(fileListingArrayList.size()+" "+(fileListingArrayList.isEmpty()));

I get output as :

2 true


I'm really confused. How can this happen?
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Laryssa,

could you please post the complete source code?
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give us some more context to this question; do you have a complete program (instead of just one line of code) that shows this behaviour?
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show a little more code - at least the declaration, addition in to the List before this print statement?

Edit - very slow...
 
Laryssa Fernandes
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, people!

I'm sorry, I had been for a lunch break. After I got back, I realized the problem. A stub that was generated using JTest caused any collection object to return true for the isEmpty() method! I hadn't realized there would be stubs for collection methods also. I'm sorry for wasting your time.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re not wasting anybody’s time. You have left useful information in case anybody has a similar problem in future, too.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!