• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Are the characters being dynamically converted to strings here?

 
Ranch Hand
Posts: 264
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I correct in saying that you can only return the characters at index 0 and 6 if they being added to a String in the return?


 
Marshal
Posts: 65467
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

wayne brandon wrote:Am I correct . . .

Yes, I think you are Have a look at the Java® Language Specification (=JLS) section about + on Strings.
What would happen if you changed the last line to?
How woyuld you get “C R” out of my name? The only number literals permitted are 1, 0, and −1.
 
Bartender
Posts: 6140
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

wayne brandon wrote:Am I correct in saying that you can only return the characters at index 0 and 6 if they being added to a String in the return?


 
Campbell Ritchie
Marshal
Posts: 65467
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you think that is what the question means, Carey, it means I have completely misunderstood it. Sorry
 
Carey Brown
Bartender
Posts: 6140
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:If you think that is what the question means, Carey, it means I have completely misunderstood it. Sorry

The question is slightly vague so I was just presenting an alternative that didn't involve making a string.
 
Bartender
Posts: 2348
102
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

wayne brandon wrote:...


I would find it very confusing for a variable named space to have no spaces. Maybe you meant to have an empty space instead ?

Campbell Ritchie wrote:...How woyuld you get “C R” out of my name? The only number literals permitted are 1, 0, and −1.


I think it can be done without literals too with the magic of streams.
 
salvin francis
Bartender
Posts: 2348
102
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:...

[Nitpick on]
I would expect at least 2 guard conditions for a method like that: a null check and a range check. Unless the method is expected to throw a StringIndexOutOfBoundsException and a NullPointerException. Even then, there should be documentation to indicate that.
[Nitpick off]
 
Campbell Ritchie
Marshal
Posts: 65467
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

salvin francis wrote:. . . with the magic of streams.

I was thinking of something simpler.
 
salvin francis
Bartender
Posts: 2348
102
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
regex ?
 
Campbell Ritchie
Marshal
Posts: 65467
249
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simpler still.
 
Master Rancher
Posts: 195
7
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I didn't use the -1 though.

Is this what you had in mind?
 
Campbell Ritchie
Marshal
Posts: 65467
249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't say you had to use all those number literals, BG. But, yes.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!