Win a copy of Event Streams in Action this week in the Java in General 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

A question about Maps and splitting Strings

 
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


So I'm doing a small task where I need to display a user entered URL's parameters. This is the code I found as a possible solution. But I can't understand why is it you can put a split String into a Map that has String for both key and value and the split method returns a String array. I obviously can't wrap my head around on why are the square brackets added after calling the split method. Is that supposed to be the index of the returned array? Care to explain fellas?

Glad to be back on the ranch, after a long pause (needed some extra knowledge to be comfortable to ask questions ), cheers.
 
Marshal
Posts: 65056
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Darko Jakimovski wrote:. . . why are the square brackets added . . . the index of the returned array? . . .

The number inside the [] is the index of the array element, yes. The String#split() method returns String[], so myString.split(someRegex)[999] represents a single String.

Glad to be back on the ranch, after a long pause (needed some extra knowledge to be comfortable to ask questions ), cheers.

Good to see you back. You would have got much extra knowledge by asking questions here.
 
Darko Jakimovski
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. And yeah... I realized that the second I posted my question. I figured it out once I asked the question myself in a forum form
 
Campbell Ritchie
Marshal
Posts: 65056
247
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a pleasure. Plese search for “rubber duck programming”. For example Wikipedia. Don't read the story about quack overflow.
 
Darko Jakimovski
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OMG! Thank you so much. I had issues in the past few days because of my total lack of knowledge in debugging. Campbell, you are the man!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!