• 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
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

The method endsWith of Path class - Java 7

 
Ranch Hand
Posts: 451
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

I have a statement

who returns



Array6_1.class

If I verified

returns false.

Instead


return true.

Can someone tell me where the mistake is?



 
Saloon Keeper
Posts: 10307
217
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A path that ends with "Array6_1.class" does not end with "class". The endsWith() method uses path elements, not characters.

The path "/foo/bar/baz/qub" has four path elements: "foo", "bar", "baz" and "qub". It ends with "qub". It doesn't end with "ub" or "b".

If you want to see if the file name ends with "class", you need to call path.getFileName().toString().endsWith("class");
 
Marshal
Posts: 64642
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API page explains exactly what Stephan has told you. There doesn't appear to be an analogous method in File.
 
Dana Ucaed
Ranch Hand
Posts: 451
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks.

This sample is from OCA/OCP Java® SE 7
Programmer I & II
Study Guide
(Exams 1Z0-803 & 1Z0-804) By Kathy Sierra pag 515.

Can you send to errata?





 
Campbell Ritchie
Marshal
Posts: 64642
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would have to be absolutely sure you do have an erratum first. What does the book say?
 
Dana Ucaed
Ranch Hand
Posts: 451
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or my parameter is wrong?

 
Dana Ucaed
Ranch Hand
Posts: 451
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw a similar post and now I can't find that post.
 
Dana Ucaed
Ranch Hand
Posts: 451
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://coderanch.com/wiki/660199/Errata, page 515.

It is a mistake.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!