The term "LINQ to Objects" refers to the use of LINQ queries with any IEnumerable<T>
.
You can use LINQ to query any enumerable collections such as Primitive Array
, Object Array
, List
, Collection
or Iterable
and so on.
The collection may be user-defined or may be returned by a JDK API.
In a basic sense, LINQ to Objects represents a new approach to collections.
In the old way, you had to write complex foreach
loops that specified how to retrieve data from a collection.
In the LINQ approach, you write declarative code that describes what you want to retrieve.
In addition, LINQ queries offer two main advantages over traditional foreach
loops:
LINQ queries also have some advantages over stream API:
foreach
loops therefore you can break loop at any time.ToCollection
, LeftJoin
and so on.In general, the more complex the operation you want to perform on the data, the more benefit you will realize by using LINQ instead of traditional iteration techniques.
forEach
stream
parallelStream
crossJoin
distinctBy
exceptBy
findIndex
findLastIndex
format
fullJoin
indexOf
intersectBy
joining
lastIndexOf
leftJoin
maxBy
minBy
rightJoin
runOnce
shuffle
toCollection
toEnumeration
toLinkedList
toLinkedMap
toLinkedSet
unionBy
File | Settings | Build, Execution, Deployment | Debugger | Data Views | Java Type Renderers
.Add
button.IterableView
in Renderer name
.java.lang.Iterable
in Apply renderer to objects of type (fully-qualified name):
.When rendering a node
section, check Use following expression:
and type DebugView.getDebuggerDisplayText(this)
.
If you get an error, press Alt + Enter
to import the class.Use list of expression:
and type **RESULT VIEW**
in the Name
column.
Type DebugView.getDebuggerProxyObject(this)
in the Expression
column.
If you get an error, press Alt + Enter
to import the class.
It is recommended to check On-demand
to enumerate the sequence if necessary.Iterable
instance, check Append default children
.Result view should be used with caution because of possible side-effects.
<dependency>
<groupId>com.bestvike</groupId>
<artifactId>linq</artifactId>
<version>6.0.0</version>
</dependency>
implementation 'com.bestvike:linq:6.0.0'
If you use java 8 or java 9, it is recommended to replace the complex return type with lombok.var or lombok.val. If you use java 10 or later, it is recommended to replace the complex return type with var.
String result = Linq.of("!@#$%^", "C", "AAA", "", "Calling Twice", "SoS", Empty)
.where(x -> x != null && x.length() > 0)
.aggregate((x, y) -> x + ", " + y);
System.out.println(result);
----
!@#$%^, C, AAA, Calling Twice, SoS
boolean result = Linq.of(9999, 0, 888, -1, 66, -777, 1, 2, -12345)
.where(x -> x > 0)
.all(x -> x % 2 == 0);
System.out.println(result);
----
false
boolean result = Linq.of(9999, 0, 888, -1, 66, -777, 1, 2, -12345)
.where(x -> x > 0)
.any(x -> x % 2 == 0);
System.out.println(result);
----
true
String result = Linq.range(3, 2).append(5).prepend(2).prepend(1).format();
System.out.println(result);
----
[1, 2, 3, 4, 5]
double result = Linq.of(5, -10, 15, 40, 28).averageInt();
System.out.println(result);
----
15.6
String result = Linq.of(1, 2).concat(Linq.of(3, 4)).format();
System.out.println(result);
----
[1, 2, 3, 4]
LINQ to Objects (Java) is released under the Apache License 2.0.
Copyright 2017-2024 济南百思为科信息工程有限公司
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。