Module: Java::java::util::Collection

Includes:
Enumerable
Defined in:
core/src/main/ruby/jruby/java/java_ext/java.util.rb

Overview

Note:

Only explicit (or customized) Ruby methods are listed here, instances will have all of their Java methods available.

java.util.Collection is enhanced (not just) to act like Ruby's `Enumerable`.

See Also:

Instance Method Summary (collapse)

Instance Method Details

- (Java::java::util::Collection) +(oth)

Join this collection with another (adding all elements).

Examples:

coll1 = java.util.ArrayList.new [1, 2]
coll2 = java.util.LinkedHashSet.new [2, 3]
coll1 + coll2 # [ 1, 2, 2, 3 ] (java.util.ArrayList)
coll2 + coll1 # [ 2, 3, 1 ] (java.util.LinkedHashSet)

Returns:



59
60
61
62
63
64
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 59

def +(oth)
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
  # nw = self.dup
  # nw.addAll(oth)
  # nw
end

- (Java::java::util::Collection) -(oth)

Subtract all elements in the provided collection from this one.

Examples:

coll1= java.util.HashSet.new [2, 3]
coll2 = java.util.LinkedList.new [1, 2]
coll1 - coll2 # [ 3 ] (java.util.HashSet)

Returns:



72
73
74
75
76
77
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 72

def -(oth)
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
  # nw = self.dup
  # nw.removeAll(oth)
  # nw
end

- (Java::java::util::Collection) <<(a)

Pushes (adds) and element into this collection.

Examples:

coll = java.util.ArrayDeque.new
coll << 111

Returns:



46
47
48
49
50
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 46

def <<(a)
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
  # add(a)
  # self
end

- (Java::java::util::Collection) dup

Return a dup-ed collection (if possible).

Examples:

arr = java.util.concurrent.CopyOnWriteArrayList.new ['0']
arr.dup # ['0'] a new CopyOnWriteArrayList instance

Returns:

Since:

  • 9.1



104
105
106
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 104

def dup
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
end

- (Object) each(&block)



13
14
15
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 13

def each(&block)
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
end

- (Object) each_with_index(&block)



18
19
20
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 18

def each_with_index(&block)
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
end

- (Object) first(count = nil) Also known as: ruby_first

Note:

Might collide with *java.util.Deque#getFirst* in which case you want to alias its ruby_ name so that the Ruby version is used e.g. `java.util.ArrayDeque.class_eval { alias first ruby_first }`

`Enumerable#first`

Since:

  • 9.1



36
37
38
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 36

def first(count = nil)
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
end

- (true, false) include?(obj) Also known as: member?

Re-implemented for efficiency, so that we do not (`#each`) loop over the collection for types where its not necessary (e.g. java.util.Set instances), uses (native) `java.util.Collection#contains`.

Returns:

  • (true, false)

See Also:

  • lang::Iterable#include?

Since:

  • 9.1.3



27
28
29
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 27

def include?(obj)
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
end

- (Integer) size Also known as: length

Returns the collection size

Returns:

  • (Integer)

    the collection size



80
81
82
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 80

def size
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
end

- (Array) to_a Also known as: entries

Converts a collection instance to an array.

Returns:

  • (Array)


92
93
94
# File 'core/src/main/ruby/jruby/java/java_ext/java.util.rb', line 92

def to_a
  # stub implemented in org.jruby.javasupport.ext.JavaUtil.java
end