4

Trying to use strip() method to get rid of white spaces around a string and for some reason strip() doesn't work. The error I get is "The method strip() is undefined for the type String".

String fullAd = "   Hello World   ";
System.out.println(fullAd.strip());
Govinda Sakhare
  • 5,009
  • 6
  • 33
  • 74
alex207e
  • 219
  • 1
  • 3
  • 6
  • 2
    `strip()` is added in java 11. Make sure you are on JDK11 or later version https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#strip() – Govinda Sakhare Jan 19 '20 at 07:29

2 Answers2

12

strip() is Java 11 functionality. Either upgrade your version or use trim() in older versions.

Guy
  • 46,488
  • 10
  • 44
  • 88
  • Is it not possible to have Java 11 on eclipse IDE? It says it's up to date, I just tried the same code on the intelliJ IDE and it worked tho, thank you. – alex207e Jan 19 '20 at 07:47
  • @alex207e You need to update the JDK rather than Eclipse, try https://stackoverflow.com/questions/12588537/how-to-change-jdk-version-for-an-eclipse-project – Guy Jan 19 '20 at 07:49
  • @alex207e it could be because. Intellij comes up with JDK packaged within it. – Govinda Sakhare Jan 19 '20 at 07:52
0

The strip() funtion is depricated after Java 11. You have to set the Target bytecode version to 11.

For my case i am using intelij. refer the screenshot below strip() function bytecode version