Skip to content

Tag: java

Populating a List with a contiguous range of integers

I’d like to have a list which contains the integers in the range 1 to 500. Is there some way to create this list using Guava (or just plain Java) without having to loop through the range and add the values individually within my own code? Answer Using Guava, you can resort to a Range: https://guava.dev/…

Changing the directory path’s forward slash to backslash

I’m using the JFile chooser, and trying to import a pdf file but; System.out.println(filelist); perfectly prints the desired outcome with forward slashes; C:/Users/raz/Documents/2pg.pdf but the doc gives an error with backslashes; java.io.FileNotFoundException: C:UsersrazDocuments2pg.pdf (The filename, …

What is an instance variable in Java?

My assignment is to make a program with an instance variable, a string, that should be input by the user. But I don’t even know what an instance variable is. What is an instance variable? How do I create one? What does it do? Answer Instance variable is the variable declared inside a class, but outside …

I’m not able to log in Tomcat Manager App

I have read a lot of topics in stackoverflow for solve my problem, but none was useful. When I tried to log in Manager App ([http://localhost:8080/manager/html][1]) using a lot of different configurations, but I always obtained 401 Unauthorized after attempted to log in using the rights credentials. I restart…

Getting Result type in Interceptor

I have Struts 2 actions with different (HTML and JSON ) result types. They use common interceptor. If needed to intercept the request, how to return a result based on given action result type? For example, my Action.ERROR forwards to JSP page. If action is JSON type I want to forward JSON error instead. Answe…

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 advantage of using them? Would it improve their performance and readability? EDIT I’ll also extend this question to longer methods. I…