| | |
String search methods indexOf and lastIndexOf
![]() |
maybe you don't know much (yet) but this is exactly the reason you are given assignments like this, to get to know the syntaxis and regulary used methods and to create your own implementation of them.
asking us to just give you the code would mean that in a week, you still have to say "I don't know much, which is why I need help".
try to understand what indexOf() and lastIndexOf() do:
a String - object can be seen as an array of chars, so the indexOf("substring") will give you the 'index' of the start of the given substring within the original String.
for instance:
just run this code, see what it does, and interprete the results you get.
I take it that lastIndexOf("") will be quite clear after the answers you've already been given.
once you figured out what the code I've posted above does, it should be quite easy to write a new implementation of this methods
asking us to just give you the code would mean that in a week, you still have to say "I don't know much, which is why I need help".
try to understand what indexOf() and lastIndexOf() do:
a String - object can be seen as an array of chars, so the indexOf("substring") will give you the 'index' of the start of the given substring within the original String.
for instance:
Java Syntax (Toggle Plain Text)
String ob = "the first String"; System.out.println("place: " + ob.indexOf("St")); System.out.println("place: " + ob.indexOf("notPresent"));
just run this code, see what it does, and interprete the results you get.
I take it that lastIndexOf("") will be quite clear after the answers you've already been given.
once you figured out what the code I've posted above does, it should be quite easy to write a new implementation of this methods
![]() |
Similar Threads
- Source Code that don't work? (Java)
Other Threads in the Java Forum
- Previous Thread: <identifier>expecter ERROR
- Next Thread: how to compare a string to an integer in java
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





