This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Array, reading input method..

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Input: 1 2 3 4
Output: [1, 2]

To me it seems that the if statement is not accessed, and of course i do not know why. Can someone tell me why is that? Or even better if i missed something, point me in the right direction because i don't see why the length of my array stays the same.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you read this article on pass-by-value vs. pass-by-reference you should be able to figure out what the dealio is.
 
S. Freeman
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
I thought that they only point to the same array, and that by modifying the array the references would "update" themselves.
Gotta blame my imagination a bit for this, because i always thought of arrays as trains, with locomotive being the reference
and pulling the wagons no matter how many there are. Did not know that i needed to tell the locomotive how many too pull.
 
Marshal
Posts: 65002
246
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never close a scanner pointing to System.inSee what happens

You could argue that you should have one Scanner and one only pointing to System.in and I would agree.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!