I have a string array which has k elements. I want to print them out using System.out.format, but the issue is that I do not know k. So essentially, I want to use something like: System.out.format(“%s %s … k times”, str1, str2, … strk); (where k is a variable) I was looking through the…
Tag: java
Set two flags in Java regex.Pattern
I need a matcher like this: and the problem is that it is not simple ASCII. I know that in this particular case I could use [u00FCu00DC] for the ü, but I need to be a bit more general (building the regex from other matcher groups). So according to javadocs: By default, case-insensitive matching assumes that o…
Maven package works but Intellij’s build fails
I have a JDK 1.7 project with a maven dependency to a local jar in my maven repo. I’m unable to build the project using Intellij, with the errors that a symbol cannot be found (the symbol is a class importing packages from the local jar) But I can successfully build the project using ‘mvn package&…
java, OutOfMemoryError: Java heap space
This class is designed to determine the language of a text; the user has to enter 4 text in english, danish, italian and latin, and then the text whose language he wants to determine. The console says I use eclipse, in Run Configurations – Arguments I wrote -Xms2g-Xmx3g. I don’t understand where i…
Change the System Brightness Programmatically
I want to change the system brightness programmatically. For that purpose I am using this code: because I heard that max value is 255. but it does nothing. Please suggest any thing that can change the brightness. Thanks Answer You can use following: In your onCreate write: Write the code to monitor the change…
Skip first line while reading CSV file in Java
I am writing a parser code to read a .csv file and parse it to XML. This is the code I have and it works, except I would like it to skip the first line in the file. So I decided to set up a HashMap but it doesn’t seem to work: This is a snippet of the main part
What is the difference between Character.isAlphabetic and Character.isLetter in Java?
What is the difference between Character.isAlphabetic() and Character.isLetter() in Java? When should one use one and when should one use the other? Answer According to the API docs, isLetter() returns true if the character has any of the following general category types: UPPERCASE_LETTER (Lu), LOWERCASE_LETT…
How to make EditText not focused when creating Activity
I’ve read the other questions discussing this, and all of them work for my layouts, except for the very first one created. At the moment, this is at the top of my onCreate method: ^ That makes it so at least the keyboard doesn’t pop up on startup, but the EditText is still focused on. This is the …
BufferInputStream vs ByteArrayInputStream
Here are three ways to read an entire file into memory before processing it: Approach A: Approach B: Approach C: Why would I prefer one approach over another? Are there any specific use-cases that call for one approach over another? Why not use a fixed-length byte[] instead? Answer Unless you need anything sp…
Java using scanner enter key pressed
I am programming using Java. I am trying write code which can recognize if the user presses the enter key in a console based program. How can I do this using java. I have been told that this can be done using either Scanner or, buffered input reader. I do not understand(or know how to use) buffered input read…