| | |
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 |
6 @param actuate android api applet application arc array arrays automation balls binary bluetooth bold business byte c++ chat class client code codesnippet collections compare component coordinates database defaultmethod detection doctype dragging ebook eclipse educational error file fractal froglogic game givemetehcodez graphics gui guitesting helpwithhomework hql html ide ideas image ingres input integer internet intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie nextline parameter php pong problem program programming project recursion recursive scanner sell server set sms sort sql string sun swing swt terminal threads tree web websites windows





