The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [java]

Java (not to be confused with JavaScript) is a class-based, object-oriented, strongly typed, reflective language and run-time environment (JRE). Java programs are compiled to bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.

Filter by
Sorted by
Tagged with
1
vote
1answer
49 views

Is there better alternative to making an optional set of elements from iterable in java?

I'm feeling uneasy with this service method that I wrote: ...
2
votes
3answers
87 views

Mapping words to letters which contains

Given sentence for example: ala ma kota, kot koduje w Javie kota I should to every letter occurring in the sentence I should map every string that this letter ...
3
votes
1answer
93 views

Find out how many laptops Molly can buy based on available money, array of quantities and array of costs

Problem description: Molly wants to purchase laptops for her school. Find out how many laptops she can purchase by comparing the vendors available. Each vendor sells the laptops in batches, with ...
2
votes
1answer
109 views

Calculate arithmetic expression represented by a string, in Java

I saw that interview question online and gave it a try: Implement a function that gets a string which represents an arithmethic expression: contains only numbers or the the operators: '+', '-', '*', '/...
0
votes
0answers
19 views

Copying cells with apache-poi

I am using apache-poi to copy excel files while also altering a few things on them. While copying, the styles, values and formulas should be retained. Yet, some formulas need to be replaced with their ...
2
votes
1answer
65 views

The most elegant way to locate two enums

I have situation where user has got options to select, and after selected any option will appear next options. For example : 1 - Add car 2 - Add motorcycle. 3 - Print cars 4 - Print motorcycles And ...
4
votes
1answer
470 views

Creating an image in Excel using the colors from an input image

I'm having some performance issues in this code and need some suggestions on how to improve it. I'm not interested in "general code style" improvements unless they have performance implications. The ...
3
votes
1answer
85 views

Ensure difference between sets

An endpoint that my application interacts with allows you to specify which fields are returned in the JSON result. My application will then map the JSON to a POJO using Jackson. Quite often I add more ...
5
votes
3answers
1k views

Project Euler #8 code implementation

Find the thirteen adjacent digits in the 1000-digit number that have the greatest product." eg, the product of the first four adjacent digits is 7 * 3 * 1 * 6 = 126 ...
4
votes
2answers
69 views

Storing variables to a map by splitting a text file

I'm currently making a social media app that contains profile details such as interests in a text file. The following code works by using markers in the text file to upload these details to map data ...
8
votes
4answers
3k views

“What is the maximum that Player 1 can win?”

This is a question that I encountered in one of the competitive coding tests. The question goes as follows: A 2-player game is being played. There is a single pile of stones. Every stone has an ...
3
votes
2answers
193 views

Generating a string in a particular format by reading data from a map

I have a processToTaskIdHolder Map which contains processId as the key and taskId as the ...
3
votes
2answers
59 views

I/O-TxtFile Line Distance Program

I am trying to write a lab/program that loops through a .txt input file. Reads an entire line of data as a string, then splits that string into an array delimited by a space. If there are 4 items in ...
7
votes
2answers
134 views

Python-style Generator in Java

I have implemented Python-style generators within Java. I might be reinventing the wheel here, but I feel that the ability to define a Generator with an anonymous class is the most flexible approach. ...
7
votes
3answers
33k views

Efficiently determining if a number is prime

Is this the most efficient way to find if a number is prime? I can't think of a better way and it seems to run pretty quickly. ...
5
votes
2answers
269 views

Converting Reverse Polish to Infix Notation in Java

I am trying to solve a programming challange that involves converting reverse polish notation to infix notation. For example: 1 3 + 2 4 5 - + / would be: ((1+3)/(2+(4-5))) My solution so far does work,...
3
votes
1answer
1k views

Android generic SQL database handler

Starting with the fact that creating the classic database handler in Android is really annoying and it usually takes a lot of time since you have to create one handler for each object, I thought at ...
3
votes
1answer
55 views

Singular linked list check and assistance

I've been working on writing data structures and methods from scratch (with minimal reference) and I'm looking for assistance on my coding style/if there's any way to optimize the methods I've ...
0
votes
2answers
114 views

Too many for-loops and conditional operators [closed]

Not please with this outcome, function works as is, but would love to simplify and prettify it. Use of one for-loop would be great and limit the use of the conditional operator. ...
6
votes
2answers
93 views

Quicksort with Insertion Sort and Improved Pivot Selection

Here's a Quicksort I had fun writing and improving, so I thought I'd post it here. In my (brief) testing it's about 15% to 20% faster than Java's Arrays.sort(). ...
11
votes
5answers
2k views

Find most “academic” implementation of doubly linked list

Recently, a company has asked me to make an implementation of a doubly linked list with unity tests to test my skills. In the task description they specified that the solution should be as academic as ...
6
votes
2answers
110 views

JavaRPN calculator

I have found that there is a distinct lack of an RPN calculator available to me, so I decided to make my own. I am still adding new functions to it, but as of now, I would like to refactor my code. ...
1
vote
1answer
49 views

Simplify and prettify function looking for max value in a list and modifying some underlying values within that list [closed]

This function is used to modify values in list List<GoogleUsageMapping> and prepare them for entering into billing system. I'm hoping this function can be ...
3
votes
1answer
202 views

Poor error handling: Throw inside Finally

I have the following code which I am running through fortify. Why it gets marked for poor error handling, throw inside finally? ...
4
votes
2answers
97 views

Data structure that retrieves each item with a specified probability

I wanted a data structure that allowed me to set the chances of randomly returning each of it's elements. For example, suppose I have a Human class. Every Human has an attribute called eyeColor. I ...
2
votes
2answers
127 views

Lottery Game in Java

In the last days I've written a number guessing game that I've posted on this site. I have now written a lottery simulation in which I tried to acknowledge the criticisms of the project mentioned ...
4
votes
2answers
94 views

Calculate the rates at which users get stuck at each stage

I completed an algorithm problem just as a personal study, and I can't help but feel like my solution is a bit needlessly complicated, although I can't figure out a better way to do it. Here's the ...
3
votes
1answer
68 views

Convert a Binary Tree to Doubly Linked List

Challenge Link on geeksforgeeks: Binary Tree to DLL Given a Binary Tree (BT), convert it to a Doubly Linked List(DLL) In-Place. The left and right pointers in nodes are to be used as previous ...
7
votes
1answer
80 views

SQLite In-memory Database That Inserts Data Read From a CSV File

I wrote this program to make a simple in-memory database using SQLite and JDBC. Requirements I was trying to accomplish are below. It should consume a CSV file, parse the data, and insert it into the ...
1
vote
0answers
41 views

Custom HashMap implementation in Java with Linear Probing

I have taken a stab at implementing a HashMap in Java. To deal with collisions I implemented sort of a LinkedList using a dataNode. I am not very confident of my implementation hence looking for some ...
35
votes
5answers
46k views

Java enum containing a hash map for look up

I have the below enum. I need to get the description by code. It is working but can it be improved still? ...
2
votes
1answer
50 views

Java file transfer through sockets

I am making a program that transfers files from one client to another. Right now I am just working on sending the file to the server and then later I will work on transferring it to the other client. ...
2
votes
2answers
799 views

Set, List and Map equality comparison with Lambda check

I'd like to be able to compare two objects with different equality checks. This should work if they're in a Set, List or ...
2
votes
2answers
89 views

RPG Map Initialization

I am working on an RPG in Java and I am using a tile-based map. The characters will not be building, so I will not need to store the maps outside of the game, but I feel as if there is a more ...
2
votes
2answers
6k views

Cookie Clicker in Java

This is my first graphical application I have made in my life (except HTML and Javascript-Applications, if that counts). It's a simple implementation of Cookie Clicker, the famous browser game. ...
3
votes
0answers
38 views

HTTP Delete,Put,Get,Post REQUEST java-ee RESTful services JPA CDI EJB

I am creating introduction app to java ee and APIs of java ee and i want know if my code is ok (like its working but if it could be done better) and what should i avoid in future ...
4
votes
1answer
73 views

Min Heap Priority Queue

This was a part of one an assignment I found online and tried to solve it myself. The objective was to implement a Priority Queue using Min Heap and use Array as the underlying data structure to ...
3
votes
1answer
66 views

Forming words that start with consonants and vowels

I am just starting to learn programming. I had already coded some functions and stuff in other languages, and whilst trying to complete this Python challenge Kevin and Stuart want to play the 'The ...
1
vote
1answer
56 views
1
vote
1answer
45 views

Selenium - Java data driven Framework suggestion

Dropdown Screenshot I have 3 dropdowns with multiple components in the UI. Have incorporated data driven java selenium framework, data is fetched from excel sheet: Excel sheet- where data is fetched ...
6
votes
2answers
75 views

Filtering a list of customers in Java based on three criteria

Let's assume that you need to filter customers based on 3 criteria: name tags assigned to customer customer's location For some reasons you have to do it directly in your program code, without ...
3
votes
1answer
285 views

Helper class for Fragments management

A Helper class for Fragment Management. The FragmentsManager class has methods to add and replace fragments. The replace method checks if the given fragment is present in backstack or not and if the ...
4
votes
3answers
121 views

Number Guessing Game in Java

This is my implementation of the famous Number Guessing Game. It is not object oriented, but the goal was to create a simple to read, procedural program. Have I accomplished this goal? ...
1
vote
0answers
77 views

Building maps for Dgraph integration tests in Java 8

I want to refactor this in Java to reduce my code duplication. ...
4
votes
2answers
83 views

Convert light-years to other representations

the code is very messy, long and I am looking how to shorten it and/or simplify it. There are a lot of repeated variables, for example; 'hourToDay' and then 'hourToDay1', 'hourToDay2' and so forth. ...
0
votes
1answer
127 views

Reverse String in Java

I've been revamping on my coding puzzles practices. What is the complexity (both time and space) for this method? ...
5
votes
2answers
248 views

Hackerrank “Almost Equal” solution

I've spent the best part of a day on this question. It is marked as Expert level. There are about fifteen submission test cases and my solution manages to satisfy the first four. However, from there ...
1
vote
0answers
82 views

Custom Knight dialer solution's time and space complexity

I recently solved the Knight Dialer problem but I'm not quite sure if I got the time complexity right; hence I'm requesting the following: 1) Time and space complexity review and explanation on why ...
3
votes
1answer
51 views

Java Networking Framework

So I've just written a framework that is supposed to make it easier to create a network-based application (client-server) using the native java.net package. I was wondering if the structure of my code ...