Schlagwörter » Java

Week of May 18th

Listening: Onward Into Battle by Vanir. This album ABSOLUTELY ROCKS, especially “Raise Your Horns”. It’s like if Amon Amarth were a little more melodious and palatable. noch 442 Wörter

Haskell

[LeetCode java Solution] - Backtracking/ Array/ Bit Manipulation - Subsets

Problem:

Given a set of distinct integers, nums, return all possible subsets.

Note:

  • Elements in a subset must be in non-descending order.
  • The solution set must not contain duplicate subsets.
  • noch 237 Wörter
Java

Java 8 默认方法和多继承

以前经常谈论的Java对比c++的一个优势是Java中没有多继承的问题。 因为Java中子类只能继承(extends)单个父类, 尽管可以实现(implements)多个接口,但是接口中只有抽象方法,方法体是空的,没有具体的方法实现,不会有方法冲突的问题。

这些都是久远的说法了,自从今年Java 8发布后, 接口中也可以定义方法了(default method)。 之所以打破以前的设计在接口中增加具体的方法, 是为了既有的成千上万的Java类库的类增加新的功能, 且不必对这些类重新进行设计。 比如, 只需在Collection接口中增加default Stream<E> stream(), 相应的Set和List接口以及它们的子类都包含此的方法, 不必为每个子类都重新copy这个方法。

这是一个折衷的设计,带来的问题就是为Java引入了多继承的问题。 我们知道, 接口可以继承接口, 类可以继承类和实现接口。 一旦继承的类和实现的接口中有相同签名的方法, 会出现什么样的状况呢? 本文将探讨各种情况的多继承, 以便能清楚的理解Java多继承的规则。

接口继承多个父接口 noch 406 Wörter

Java

[LeetCode Java solution] - Backtracking - Combinations

Problem:

Given two integers n and k, return all possible combinations of k numbers out of 1 … n.

For example,
If n = 4 and k = 2, a solution is: noch 194 Wörter

Java

Borobudur Sunrise by gumilangaryo

The picture was taken on top of the Borobudur Temple during sunrise.

As Seen on 500px – May 23, 2015 at 12:51AM

Travel

Borobudur Sunrise by gumilangaryo

The picture was taken on top of the Borobudur Temple during sunrise.

As Seen on 500px – May 23, 2015 at 12:51AM

Travel

[LeetCode java solution] - String/Hashtable - Anagrams

Problem:

Given an array of strings, return all groups of strings that are anagrams.

Note: All inputs will be in lower-case.

Method:

Create a HashMap: noch 160 Wörter

Java