tagged [java]

'Optional.get()' without 'isPresent()' check

'Optional.get()' without 'isPresent()' check I have the following search code in Java: I was wishing to find column by name and return first one found. I understand there is a case when nothing found ...

6 Feb at 00:39

What is the difference between 'java', 'javaw', and 'javaws'?

What is the difference between 'java', 'javaw', and 'javaws'? What is the difference between `java`, `javaw`, and `javaws`? I have found that on Windows most usage of Java is done using `javaw`.

14 Sep at 07:53

Get enum values as List of String in Java 8

Get enum values as List of String in Java 8 Is there any Java 8 method or easy way, which returns Enum values as a List of String, like:

6 Apr at 05:54

Converting between java.time.LocalDateTime and java.util.Date

Converting between java.time.LocalDateTime and java.util.Date Java 8 has a completely new API for date and time. One of the most useful classes in this API is `LocalDateTime`, for holding a timezone-i...

19 Oct at 21:27

How do I use a delimiter with Scanner.useDelimiter in Java?

How do I use a delimiter with Scanner.useDelimiter in Java? I don't understand how delimiter works, can someone explain this in layman terms?

23 Mar at 06:6

Java 8 Distinct by property

Java 8 Distinct by property In Java 8 how can I filter a collection using the `Stream` API by checking the distinctness of a property of each object? For example I have a list of `Person` object and I...

Java: print contents of text file to screen

Java: print contents of text file to screen I have a text file named `foo.txt`, and its contents are as below: > thisistext How would I print this exact file to the screen in Java 7?

20 Jun at 09:12

Most concise way to convert a Set<T> to a List<T>

Most concise way to convert a Set to a List For example, I am currently doing this: Can you beat this ?

13 Jan at 11:7

Java 8: How do I work with exception throwing methods in streams?

Java 8: How do I work with exception throwing methods in streams? Suppose I have a class and a method Now I would like to call foo for each instance of `A` delivered by a stream like: Question: How do...

Image.createImage problem in J2ME

Image.createImage problem in J2ME I tried this on J2ME I hit this error: `java.lang.IllegalArgumentException:` How do I solve this?

7 Nov at 13:39

how to take user input in Array using java?

how to take user input in Array using java? how to take user input in Array using Java? i.e we are not initializing it by ourself in our program but the user is going to give its value.. please guide!...

15 May at 12:47

How to convert java.lang.Object to ArrayList?

How to convert java.lang.Object to ArrayList? I have a valid `ArrayList` object in the form of `java.lang.Object`. I have to again convert the `Object` to an `ArrayList`. I tried this: But it is print...

24 Dec at 04:58

Find first element by predicate

Find first element by predicate I've just started playing with Java 8 lambdas and I'm trying to implement some of the things that I'm used to in functional languages. For example, most functional lang...

6 Sep at 19:44

How to set Oracle's Java as the default Java in Ubuntu?

How to set Oracle's Java as the default Java in Ubuntu? How do I change the value of `JAVA_HOME` in Ubuntu to point to Oracle's Java? Should it point to `java-6-sun` or `java-6-sun-1.6.0.24` ?

25 Mar at 17:47

Java 8 Iterable.forEach() vs foreach loop

Java 8 Iterable.forEach() vs foreach loop Which of the following is better practice in Java 8? Java 8: Java 7: I have lots of for loops that could be "simplified" with lambdas, but is there really any...

4 Oct at 01:40

How to subtract X day from a Date object in Java?

How to subtract X day from a Date object in Java? I want to do something like: How to do it?

What's the difference between next() and nextLine() methods from Scanner class?

What's the difference between next() and nextLine() methods from Scanner class? What is the main difference between `next()` and `nextLine()`? My main goal is to read the all text using a `Scanner` wh...

7 Apr at 06:48

How do I convert a Java 8 IntStream to a List?

How do I convert a Java 8 IntStream to a List? I'm looking at the docs for the `IntStream`, and I see an `toArray` method, but no way to go directly to a `List` Surely there is a way to convert a `Str...

15 May at 10:3

How to set CATALINA_HOME variable in windows 7?

How to set CATALINA_HOME variable in windows 7? I have downloaded `apache-tomcat-7.0.35`. My JDK version is `jdk1.6.0_27`. How do I configure `CATALINA_HOME` as an environment variable and how do I ru...

Java 8 Stream API to find Unique Object matching a property value

Java 8 Stream API to find Unique Object matching a property value Find the object matching with a Property value from a Collection using Java 8 Stream. Person attributes -> Name, Phone, Email. Iterate...

30 Oct at 02:1

How do I join two lists in Java?

How do I join two lists in Java? Conditions: do not modify the original lists; JDK only, no external libraries. Bonus points for a one-liner or a JDK 1.3 version. Is there a simpler way than:

7 Apr at 12:12

How can I throw CHECKED exceptions from inside Java 8 lambdas/streams?

How can I throw CHECKED exceptions from inside Java 8 lambdas/streams? How can I throw CHECKED exceptions from inside Java 8 lambda, used in a stream for example? In other words, I want to make code l...

Java Logging vs Log4J

Java Logging vs Log4J Is it still worth to add the log4j library to a Java 5 project just to log let's say some exceptions to a file with some nice rollover settings. Or will the standard util.logging...

5 Dec at 15:27

JSON Java 8 LocalDateTime format in Spring Boot

JSON Java 8 LocalDateTime format in Spring Boot I'm having a small problem with formatting a Java 8 LocalDateTime in my Spring Boot Application. With 'normal' dates I have no problem, but the LocalDat...

30 Apr at 00:15

Format LocalDateTime with Timezone in Java8

Format LocalDateTime with Timezone in Java8 I have the this simple code: Then I will get following exception: ``` java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: OffsetSeconds ...

3 Sep at 17:31