> Java
>
> ```
> String name = "John";
> String lastName = "Smith";
> String text = "My name is: " + name + " " + lastName;
> String otherText = "My name is: " + name.substring(2);
> ```
三元运算符
=====
val text = if (x > 5)
"x > 5"
else "x <= 5"
> Java
>
> ```
> String text = x > 5 ? "x > 5" : "x <= 5";
> ```
位运算
===
val andResult = a and b
val orResult = a or b
val xorResult = a xor b
val rightShift = a shr 2
val leftShift = a shl 2
> Java
>
> ```
> final int andResult = a & b;
> final int orResult = a | b;
> final int xorResult = a ^ b;
> final int rightShift = a >> 2;
> final int leftShift = a << 2;
> ```
is/as/in
========
if (x is Int) { }
val text = other as String
if (x in 0…10) { }
> Java
>
> ```
> if(x instanceof Integer){ }
> final String text = (String) other;
> if(x >= 0 && x <= 10 ){}
> ```
when
====
val x = // value
val xResult = when (x) {
0, 11 -> “0 or 11”
in 1…10 -> “from 1 to 10”
!in 12…14 -> “not from 12 to 14”
else -> if (isOdd(x)) { “is odd” } else { “otherwise” }
}
val y = // value
val yResult = when {
isNegative(y) -> “is Negative”
isZero(y) -> “is Zero”
isOdd(y) -> “is odd”
else -> “otherwise”
}
> Java
>
> ```
> final int x = // value;
> final String xResult;
>
> switch (x){
> case 0:
> case 11:
> xResult = "0 or 11";
> break;
> case 1:
> case 2:
> //...
> case 10:
> xResult = "from 1 to 10";
> break;
> default:
> if(x < 12 && x > 14) {
> xResult = "not from 12 to 14";
> break;
> }
>
> if(isOdd(x)) {
> xResult = "is odd";
> break;
> }
>
> xResult = "otherwise";
> }
>
> final int y = // value;
> final String yResult;
>
> if(isNegative(y)){
> yResult = "is Negative";
> } else if(isZero(y)){
> yResult = "is Zero";
> }else if(isOdd(y)){
> yResult = "is Odd";
> }else {
> yResult = "otherwise";
> }
> ```
for
===
for (i in 1 until 11) { }
for (i in 1…10 step 2) {}
for (item in collection) {}
for ((index, item) in collection.withIndex()) {}
for ((key, value) in map) {}
> Java
>
> ```
> for (int i = 1; i < 11 ; i++) { }
>
> for (int i = 1; i < 11 ; i+=2) { }
>
> for (String item : collection) { }
>
> for (Map.Entry<String, String> entry: map.entrySet()) { }
> ```
集合
==
val numbers = listOf(1, 2, 3)
val map = mapOf(1 to “One”,
2 to "Two",
3 to "Three")
> Java
>
> ```
> final List<Integer> numbers = Arrays.asList(1, 2, 3);
>
> final Map<Integer, String> map = new HashMap<Integer, String>();
> map.put(1, "One");
> map.put(2, "Two");
> map.put(3, "Three");
>
> // Java 9
> final List<Integer> numbers = List.of(1, 2, 3);
>
> final Map<Integer, String> map = Map.of(1, "One",
> 2, "Two",
> 3, "Three");
> ```
forEach
-------
numbers.forEach {
println(it)
}
> Java
>
> ```
> for (int number : numbers) {
> System.out.println(number);
> }
> ```
filter
------
numbers.filter { it > 5 }
.forEach { println(it) }
> Java
>
> ```
> for (int number : numbers) {
> if(number > 5) {
> System.out.println(number);
> }
> }
> ```
groupBy
-------
val groups = numbers.groupBy {
if (it and 1 == 0) "even" else "odd"
}
> Java
>
> ```
> final Map<String, List<Integer>> groups = new HashMap<>();
> for (int number : numbers) {
> if((number & 1) == 0){
> if(!groups.containsKey("even")){
> groups.put("even", new ArrayList<>());
> }
>
> groups.get("even").add(number);
> continue;
> }
>
> if(!groups.containsKey("odd")){
> groups.put("odd", new ArrayList<>());
> }
>
> groups.get("odd").add(number);
> }
>
> // or
>
> Map<String, List<Integer>> groups = items.stream().collect(
> Collectors.groupingBy(item -> (item & 1) == 0 ? "even" : "odd")
> );
> ```
partition
---------
val (evens, odds) = numbers.partition { it and 1 == 0 }
> Java
>
> ```
> final List<Integer> evens = new ArrayList<>();
> final List<Integer> odds = new ArrayList<>();
> for (int number : numbers){
> if ((number & 1) == 0) {
> evens.add(number);
> }else {
> odds.add(number);
> }
> }
> ```
sortedBy
--------
# 写在最后
作为一名即将求职的程序员,面对一个可能跟近些年非常不同的 2019 年,你的就业机会和风口会出现在哪里?在这种新环境下,工作应该选择大厂还是小公司?已有几年工作经验的老兵,又应该如何保持和提升自身竞争力,转被动为主动?
**就目前大环境来看,跳槽成功的难度比往年高很多。一个明显的感受:今年的面试,无论一面还是二面,都很考验Java程序员的技术功底。**
最近我整理了一份复习用的面试题及面试高频的考点题及技术点梳理成一份“**Java经典面试问题(含答案解析).pdf**和一份网上搜集的“**Java程序员面试笔试真题库.pdf**”(实际上比预期多花了不少精力),**包含分布式架构、高可扩展、高性能、高并发、Jvm性能调优、Spring,MyBatis,Nginx源码分析,Redis,ActiveMQ、Mycat、Netty、Kafka、Mysql、Zookeeper、Tomcat、Docker、Dubbo、Nginx等多个知识点高级进阶干货!**
**由于篇幅有限,为了方便大家观看,这里以图片的形式给大家展示部分的目录和答案截图!**
![](https://img-blog.csdnimg.cn/img_convert/fe55129dbe8c730bdc671d171358130a.webp?x-oss-process=image/format,png)
### Java经典面试问题(含答案解析)
![](https://img-blog.csdnimg.cn/img_convert/2e5f89cb891eb1c1de1782909ca97c46.webp?x-oss-process=image/format,png)
### 阿里巴巴技术笔试心得
![](https://img-blog.csdnimg.cn/img_convert/54fe0079d1de5878f374948b552a3b78.webp?x-oss-process=image/format,png)
几年工作经验的老兵,又应该如何保持和提升自身竞争力,转被动为主动?
**就目前大环境来看,跳槽成功的难度比往年高很多。一个明显的感受:今年的面试,无论一面还是二面,都很考验Java程序员的技术功底。**
最近我整理了一份复习用的面试题及面试高频的考点题及技术点梳理成一份“**Java经典面试问题(含答案解析).pdf**和一份网上搜集的“**Java程序员面试笔试真题库.pdf**”(实际上比预期多花了不少精力),**包含分布式架构、高可扩展、高性能、高并发、Jvm性能调优、Spring,MyBatis,Nginx源码分析,Redis,ActiveMQ、Mycat、Netty、Kafka、Mysql、Zookeeper、Tomcat、Docker、Dubbo、Nginx等多个知识点高级进阶干货!**
**由于篇幅有限,为了方便大家观看,这里以图片的形式给大家展示部分的目录和答案截图!**
[外链图片转存中...(img-GL84qPc4-1718875709889)]
### Java经典面试问题(含答案解析)
[外链图片转存中...(img-ZmyoSbfD-1718875709890)]
### 阿里巴巴技术笔试心得
[外链图片转存中...(img-iJRxD4Xr-1718875709890)]