will it happend to java too?

J

John C. Bollinger

puzzlecracker said:

Not really.
-any comments, suggestions, last minute issues?

Comment: the folks over in comp.programming seem to be just as good at
recognizing tiresome people as we are over here.

Suggestion: if you wish to argue c++ vs. Java, as seems to be the case,
then the most appropriate Java forum would be comp.lang.java.advocacy.

Last minute issue: *plonk*
 
T

Thomas Hawtin

Darryl said:
String a = "abcdefg";
String b = "cde";
boolean isSubset = a.indexOf(b) != -1;

Why would we need a specific function to do that for us?

Actually there is, since 5.0, a method to check indexOf against -1.

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#contains(java.lang.CharSequence)


The original question was about a subset rather than a subsequence,
which shows a failure to understand the nature of string. A string is a
sequence of characters/code points.

If you want to perform set operations, use a set.

Collection<Character> a = Arrays.asList(new Character[] {
'a', 'b', 'c', 'd', 'e', 'f', 'g'
});
Set<Character> b = new HashSet<Character>(Arrays.asList(new Character[]{
'a', 'd', 'g'
}));
b.removeAll(a);
boolean isSubset = b.isEmpty();

(Usual disclaimer. Not optimised.)

Tom Hawtin
 
R

Roedy Green

If you want to perform set operations, use a set.

Collection<Character> a = Arrays.asList(new Character[] {
'a', 'b', 'c', 'd', 'e', 'f', 'g'
});
Set<Character> b = new HashSet<Character>(Arrays.asList(new Character[]{
'a', 'd', 'g'
}));
b.removeAll(a);


Another approach is to create a java.util.bitSet of 64K bits (8k
bytes) (or subrange of interest). You index by character number to
decide if it in the set of interest.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top