java-8

InetAddress java 8 is not getting the hostname

送分小仙女□ 提交于 2019-12-30 10:07:50
问题 InetAddress.getLocalHost().getHostName() is no more getting the name of the HostName since I switched to java 8 ... with the jdk1.8 the InetAddress.getLocalHost().getHostName() returns "localhost". Before (when I was using jdk1.6) it gives me the right hostname (which is "ACTION03") according to the network config : cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=ACTION03 any help ? 回答1: Works for me on Linux (Ubuntu 14.04) with Java 1.8.0_05. public class HostName { public static void

InetAddress java 8 is not getting the hostname

会有一股神秘感。 提交于 2019-12-30 10:07:13
问题 InetAddress.getLocalHost().getHostName() is no more getting the name of the HostName since I switched to java 8 ... with the jdk1.8 the InetAddress.getLocalHost().getHostName() returns "localhost". Before (when I was using jdk1.6) it gives me the right hostname (which is "ACTION03") according to the network config : cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=ACTION03 any help ? 回答1: Works for me on Linux (Ubuntu 14.04) with Java 1.8.0_05. public class HostName { public static void

Selecting a period or a date using ONE JavaFX 8 DatePicker

邮差的信 提交于 2019-12-30 09:41:26
问题 On the application I am currently working, it is necessary to select a single date or a period from the same JavaFX 8 DatePicker. The preferred way of doing this would be as follows: Selecting a single date - same as default behaviour of the DatePicker. Selecting a period - select start/end date by holding down the mouse button and drag to the desired end/start date. When the mouse button is released you have defined your period. The fact that you cannot select dates other than those

Partition java streams in categories [duplicate]

假装没事ソ 提交于 2019-12-30 09:28:10
问题 This question already has answers here : Java 8 List<V> into Map<K, V> (21 answers) Closed 2 years ago . I have a stream<A> , where class A { String category(); // ... } I would like to get a map<String, list<A>> , where the original stream is partitioned into sublists based on the value of category(). It is pretty trivial to have it implemented using a for loop, but is it possible to get a more elegant solution harnessing java streams? EXAMPLE: Given {[a, xyz], [a, zyx], [b, abc]} , I would

Java Streams | groupingBy same elements

家住魔仙堡 提交于 2019-12-30 09:05:11
问题 I have a stream of words and I would like to sort them according to the occurrence of same elements (=words). e.g.: {hello, world, hello} to Map<String, List<String>> hello, {hello, hello} world, {world} What i have so far: Map<Object, List<String>> list = streamofWords.collect(Collectors.groupingBy(???)); Problem 1: The stream seems to lose the information that he is processing Strings, therefore the compiler forces me to change the type to Object, List Problem 2: I don't know what to put

How do I sort a List of TreeSets with java8 streams

≡放荡痞女 提交于 2019-12-30 08:28:39
问题 My list contains sets like [1,3,5][2,6,4] etc, all of the same size. I tried doing this but it doesn't seem to work. List<TreeSet<T>> block; for(TreeSet<T> t : block){ block.stream().sorted((n,m)->n.compareTo(m)).collect(Collectors.toSet()); } The end result I want is [1,2,3][4,5,6] . I could try to add all the elements in an ArrayList and sort that out then make a new List of TreeSet 's. But is there is some kind of one liner? UPDATE: List<T> list=new ArrayList<T>(); for(TreeSet<T> t : block

Best way to install java 8 using docker?

自古美人都是妖i 提交于 2019-12-30 08:27:13
问题 I have a dockerfile that starts with the following line FROM java:8 I thought this is supposed to pull the image from the docker container registry and install. no? when I run the java command inside my container I get the following error ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. What is the easiest and the best way to install java 8(openjdk version) using docker? UPDATE: RUN apt-get install -y --no-install-recommends software-properties-common RUN add-apt

Java label irregularity (possible bug?)

我的未来我决定 提交于 2019-12-30 08:23:14
问题 If we look at the Java standard §14.7, we see that statements may have label prefixes, e.g.: LabeledStatement:       Identifier : Statement In theory, a label should be able to label any succeeding statement. So, for example, the following compiles accordingly: public class Test { public static void main(String[] args) { hello: return; } } Intuitively, this also compiles: public class Test { int i; public static void main(String[] args) { Test t = new Test(); label: t.i = 2; } } But the

using forEach to iterate over varArgs [duplicate]

ぃ、小莉子 提交于 2019-12-30 08:13:12
问题 This question already has answers here : How can I create a stream from an array? (6 answers) Closed 4 years ago . Can I use forEach() or stream() on varArgs ? protected void getSomeIds (List<String>... varArgs) { for(List lst:varArgs) { System.out.println("This works"); } //Following does not compile varArgs.forEach(); // nor varArgs.stream(); } 回答1: Varargs behave similarly to arrays, so you can get a Stream of the varargs using Stream.of : Stream<List<String>> stream = Stream.of (varArgs);

Parsing date and AM/PM using java 8 DateTime API

僤鯓⒐⒋嵵緔 提交于 2019-12-30 08:08:14
问题 I'm trying to parse a date time string using java 8 DateTime API. The string to parse contains date, month, year and AM/PM marker such as 17/02/2015 PM . I use the following pattern: dd/MM/yyyy aa and I expect the parsed LocalDateTime time part to be set at 12:00:00 or 00:00:00 depending on the AM/PM marker. Using the former java.text.SimpleDateFormat API, the parsing works as expected using this pattern. But when i use java 8 DateTime API and run the following code: LocalDateTime.parse("17