aspose file tools*
The moose likes Cattle Drive and the fly likes The split() method contains an indexof search...... cannot find explanation of this. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "The split() method contains an indexof search...... cannot find explanation of this." Watch "The split() method contains an indexof search...... cannot find explanation of this." New topic
Author

The split() method contains an indexof search...... cannot find explanation of this.

margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 318
    
    6

My nitpicker suggested that ......The split() method contains an indexof search. I see the split method in the string class but I can't find a split() class in the JDE and dont understand this suggestion. Any ideas welcome. Thank you.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12
The Java API shows two variations of the split() method. Neither one uses the term "indexof search". However, the split method returns an array, the elements of which are indexed. Could that be the index you are searching for?


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 318
    
    6

Hi Marilyn,
However, the split method returns an array

I have used the string.split to load an array without any problem. I understand the two variations of the command, the second variation limits the number of times the regular expression will be looked for. I don't understand what was meant either and when I asked Paul he said to post the question about indexof in the Cattle Drive forum.

Here is the whole conversation...


Ask on the cattle drive forum
>On Wed, Oct 21, 2009 at 8:27 PM, MM Gillon wrote:
> I am really confused about this comment.
>
>> The split() method contains an indexof search. Any
>> chance that you
>> can rewrite this toInt() so that it does this just once?
>
> The split() is a method in string class and string has the indexOf() but I can't find a split class in the Sun JDE and I only see two versions of the split method in the string reference.
>
> http://java.sun.com/j2se/1.4.2/docs/api/
>


Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Okay Margaret, I may not be helping here, and I haven't used split() (maybe it's new, or maybe my solution took a different approach), but two things stand out about your question.

1) split() is a method of the string class, you said you were looking for a class named split()? Is your wording correct here, or am I missing something?

2)Obviously you are using split() to return an array. Would there be any advantage in changing your approach and returning something else instead?
margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 318
    
    6

Hi Carol,

The quote above about using the split() method is an email Paul sent to me.... that is why I am so confused !!!


Paul wrote......
>> The split() method contains an indexof search. Any
>> chance that you
>> can rewrite this toInt() so that it does this just once?


2) Obviously you are using split() to return an array. Would there be any advantage in changing your approach and returning something else instead?


Using the string.split was suggest by Paul, I was doing a string.indexOf in tandem with a string.substring to parse the string prior to using string.split

At this point I am not worried about the assignment as much as trying to figure out what Paul meant in the comment
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20693
    ∞

There is no "split" class. It is a method in the String class.

Margaret,

Consider the indexOf() method. I want you to suppose for a moment that you write the indexOf() method. How would you go about it? Maybe it might even be a good idea to write a bit of code just to help you think through how it works.

Next, consider the split() method. I want you to do the exact same thing.

A solution you sent me used both methods.

I would like to suggest that each of these methods are rather time consuming - not particularly efficient. They are well written and all, but to do what they do just takes a bit of time.

I would even go so far as to speculate that one could create a method much like split() that uses indexOf(). In other words, the functionality of split() is sort of a big brother to indexOf().

So, in your solution, you used indexOf() and you then threw that information away and called split(). I was attempting to suggest that you instead use just one or the other, but not both. And just once. After all, a call to either is a wee bit expensive.



permaculture Wood Burning Stoves 2.0 - 4-DVD set
margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 318
    
    6

I see. You were making an abstract reference about how split() works and I was looking for a literal function with the name and not understanding your thought process. Thank you for clearing that up.

A solution you sent me used both methods...... I was attempting to suggest that you instead use just one or the other, but not both. And just once. After all, a call to either is a wee bit expensive.


I did come to understand about the overhead of using both functions methods and in latest version the indexOf() was removed.

paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20693
    ∞

I remember doing development before java and having something called a "function". In java, there is something similar called a "method".

I made the change. You need to make the change too.

There is, literally, a method called split().

margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 318
    
    6

I remember doing development before java and having something called a "function". In java, there is something similar called a "method".


Yes, string class, split method, understood.

I made the change. You need to make the change too.


I am.... but In the languages I work in both still exist. They are interchangable in some revisions of the language and strictly defined in others... I support both and have to use both words with other developers. I am working to correct my usage in the Java forums.

There is, literally, a method called split().

Yes, got it.... my issue was that the way I originally read your comment I was looking for string.split.indexOf() or split.indexOf()
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Ain't this a great way to learn?
margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 318
    
    6

Ain't this a great way to learn?




YES

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The split() method contains an indexof search...... cannot find explanation of this.