Tagged Questions
-3
votes
2answers
19 views
Syntax error on token 'else', { expected
I am a bit new to Java and I tried to make this simple program of writing in the right string to make it print out "Password entered" and when something else was entered it would say "Wrong password". ...
0
votes
1answer
27 views
Replace part of the string from reference string
I have a String ArrayList consisting alphabets followed by a digit as a suffix to each of the alphabet.
ArrayList <String> baseOctave = new ArrayList();
baseOctave.add("S1");
...
-1
votes
1answer
26 views
Calculator parse user input using regex
Have the next regex /+|-^[(-], which I use in String.split(regex) method.
I want to split in situations when there is plus or minus, but if it's minus then don't split if before him there is opening ...
1
vote
2answers
42 views
Captalizing Strings Automatically before Persist
I have the following situation: my application needs to save all the strings typed by the user capitalized on the database, no matter how the user types it, the application needs to capitalize ...
-1
votes
2answers
29 views
How to replace multiple space to single space in string (java)? [duplicate]
What i want to do is to replace multiple space to single space in a string.
I have string variable
String text = "i want to replace multiple space";
and i want it change into
String text = ...
1
vote
2answers
59 views
Java Split string into array, by size and only split after delimiters
I have a many string wich are really randomly sized like : 5 chars to 12000 randomly.
Eg:
String 1 : A,b,C,d
String 2 :23,343,342,4535,4535,453,234,
String 3 : ...
1
vote
5answers
48 views
I wanted to get sub string
Currently I am using code like this
while (fileName.endsWith(".csv")) {
fileName = fileName.substring(0, fileName.lastIndexOf(FILE_SUFFIX_CSV));
if (fileName.trim().isEmpty()) {
...
0
votes
0answers
57 views
Trying to send an array to a method that would split each element using String.split()
I have created an array that takes each line of a txt file and stores it in each index. Now, I need to split each of them using String.split(). I have a method that would correctly do the split ...
1
vote
3answers
38 views
How to get the second word from Java Scanner input?
Maybe it just requires a method of String but I really need to get the value of the second word from Scanner input received like this:
Scanner in = new Scanner(System.in);
String a;
a = ...
0
votes
5answers
61 views
How to remove single character in a string (java)?
I have a variable of type string, I want to remove all single characters from it.
example:
String test = "p testing t testing";
I want the output to be like this:
String test = "testing ...
-3
votes
2answers
29 views
Read, Find the string and then read the string
I would like to write a java program which reads a line, searches for a string in the line, and then reads the characters which are after the searched-for string.
For instance, say I read in the ...
0
votes
4answers
40 views
Split string at commas
I have some strings in Java, which look like the following:
String s = ""Aac 1Zl Aachen",,DE,5048.850N,00611.483E,189.0m,1,,,,"AACHEN""
I wanna split the string at every comma and assign the ...
0
votes
0answers
15 views
Assigning the value of a string without using return in JNI
I have accessed the value of a String present in my Java file Abc.java through the function accessfield().
I need to reassign a value for that particular string without using return, since my method ...
0
votes
5answers
55 views
How to know if the string variabel contains only space in java?
I have a variabel of string, i want to replace the string with "null" if the variabel contains only a space or multiple of space. how to do it?.
-1
votes
5answers
68 views
Java counting program
I want to make a program to count characters, words and lines from an input text and stops when read a point(.)
This i what i have done so far...
import java.util.Scanner;
import java.io.*;
...
-1
votes
1answer
28 views
Why does my String here not work? JAVA [on hold]
Im trying to figure out, why at compile time in my first method here, the string message gives an error, where as in my second method when initialised to null it works just fine. It was my ...
0
votes
9answers
59 views
To count the no. of times a char occur in a string
i have done this
public static void main(String[] args) {
int a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i1=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z = 0;
/initialized the variable ...
-2
votes
3answers
69 views
Java String to Json & vice versa
I want to covert a string based protocol to Json, Performance is key
The String based protocol is something like
<START>A12B13C14D15<END>
and json is
{'A':12,'B':13,'C':14,'D':15}
...
0
votes
2answers
80 views
How to pass string value via putString in Java
In my activity, I'm not able to access a string via putString in Java. Here is the code:
private void setButtonListeners()
{
SharedPreferences sp = this.getSharedPreferences("favs", ...
1
vote
4answers
90 views
Most efficient way to print all variations of a String?
If I have a 7 word String (I like it when it rains hard) and I want to print every variation of it that is
a) Greater than two words
and
b) Not changing the original word order.
How best to ...
1
vote
3answers
51 views
Convert String to Long,No built in library
I wrote Java code to convert String to long. However, when dealing with overflow problem, I don't have clues how to solve it. If a number is overflowed, computer believe every number is legal in ...
0
votes
3answers
42 views
String memory allocation and string pool concepts
What is the difference between these two assignments, in terms of memory allocation and String pools.
String b = "sunil" + "khokhar";
and
String a = "sunil";
String b = a + "khokhar";
0
votes
3answers
41 views
How to assign value to several numbers of string?
I have c1,c2,c3,c4... etc
Every c has value of 2 letter string, for example AX or BY or CZ
then I split that string so I have cArray with array of 2 strings.
My question is how to change string value ...
0
votes
4answers
40 views
How to convert phonetic phone number to numeric phone number?
public class Driver
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String phoneNumber;
System.out.print("Enter a phonetic phone ...
0
votes
0answers
40 views
String memory allocation in java for null and double quotes [duplicate]
String str = "";
and
String str = null;
How memory will be allocate in java?
Please help.
0
votes
6answers
41 views
Comparing Strings in Java .equals()
I'm trying to filter the user's input to make sure its a max of 4 digits and it's not an empty string. Whether I leave it blank or I enter a number, !strInput.equals(null) still comes up true. Am I ...
1
vote
1answer
39 views
Reversing a string, not working
I commented out the options pane to get a quick view of the output..I'm not sure what I'm doing wrong and I just started a computer science class. My output is the same as the input but I know the ...
0
votes
3answers
30 views
How do you write a code in java that randomizes entered values?
I'd like to write a code in java that would take strings entered by the user and output them in a random order. Does anyone have a solution to this? I only have a few weeks' programming experience, so ...
0
votes
1answer
42 views
Efficient search for words in string
I have a dictionary containing a list of words and I have a string URL. I want to find all the words contained in the URL after it has been decomposed into tokens using delimiters. Right now, I am ...
0
votes
1answer
60 views
Storage of /n in String object. Java
i have a little missbehaviour in my program.
One of his methods should build an string and then return it to be displayed in an Java Swing GUI.
In some parts of it, it needs to store a "line break" ...
1
vote
3answers
57 views
Remove last n lines (sentences) in a String in Java
I am looking for an efficient way to remove last n lines from a String. Efficient as in- fast performing as well as something that does not create too may objects. Therefore would like to stay away ...
-1
votes
1answer
31 views
How to load a resource name procedurally?
A little context, I'm using Eclipse to write an android game/app using Java. One function returns a variable "flag" which tells a render function to draw a window on top of the screen. My code looks ...
0
votes
1answer
26 views
String value from a JTable to BigDecimal throws Java.lang.NumberFormatException
I am making a graphing calculator that allows the calculation of data with errors (i.e. 5 +-0.02). I have created an object named Numbers3 which in its attributes has a BigDecimal variable. When I ...
1
vote
5answers
74 views
How to check wether a string contains the search items
I have a String and a String[] filled with search items.
How can I check whether my String contains all of the search items?
Here is an example:
Case 1:
String text = "this is a stupid test";
...
0
votes
1answer
33 views
Java ternary Operator NPE autoboxing String [duplicate]
this simple code is throwing NPE i dont understand why?
private Boolean isSangByJohnOrPaul()
{
final String sangBy = "harrison";
final Boolean result = sangBy.equals("lennon")?true
...
-8
votes
0answers
36 views
vertical that accepts a string as its parameter [on hold]
Write a method called vertical that accepts a string as its parameter and prints each letter of the string on separate lines. For example, a call of vertical("hey now") should produce the following ...
-4
votes
0answers
46 views
I have a String =“(123)(456)”; I want to take only no and convert that into the Integer and add as 123 + 456 = 579 [duplicate]
I have a String ="(123)(456)";
I want to take only no and convert that into the Integer and add as 123 + 456 = 579.
0
votes
4answers
48 views
Print Words In String Backwards
So I'm having a bit of trouble with my Computer Science class. I need to write some code that will take a string and print it backwards in reverse word order. He told me to find an empty space, then ...
0
votes
3answers
34 views
Converting timestamp String in a unique Primary Key
I'd like to transform a String (from an XML file) to a DB Primary Key using Java 7.
In particular, I would like to make sure that this values are unique, positive and respect the DB primary key ...
0
votes
2answers
44 views
How to separate string in text file into different array (java)
I have a text file that consist of string. What i want to do is to separate the string with "[ham]" and the string with "[spam]" inside to the different array, how can i do that, i think about to use ...
0
votes
1answer
61 views
Java want to improve a code snip
I wish to improve this code:
for (int i = 0; i < a.length(); i++) {
for (int j = 0; j < b.length(); j++) {
if (arrayA[i] == arrayB[j]) {
arrayA[i] = ' ';
...
0
votes
1answer
27 views
Using replaceAll on a String for replacing \\s by \t not working. Bug? [on hold]
I created this code for replacing spaces by tab:
String r="Tabular este texto".replaceAll("\\s","\t");
System.out.println(r);
But when I try to run it, what I get is this:
Tabular este texto
...
0
votes
4answers
58 views
How can I separate a string in Java from full name to last name, first name?
How would you take a string that you have input from the keyboard and rearrange it? For example, in my case I am asking the user to import a person's name in "last name, first name" format. I then ...
0
votes
2answers
34 views
Saving the values of a string to another class and retrieving it
I am currently trying to save the values of a string to another class file in JAVA called Memory.JAVA. The reason why I am doing this is because variables are not saved outside the Try - Catch ...
1
vote
1answer
23 views
Using addFirst and addLast methods with StringBuilder in java?
I would like to use (For a string array)
public void addFirst(String Element)
{
}
and
public void addLast(String Element){
}
I know the add I would use
public void add(int index, ...
-6
votes
2answers
72 views
Using answer in if [on hold]
Java is very new to me, and i ran into this problem. This is my code:
String answer;
System.out.println("Choose a day");
answer = tastatur.nextLine();
if(svar.equals("saturday"))
...
-2
votes
1answer
65 views
Why does == return true for a String comparison? [duplicate]
I have previously asked a question about comparing 2 strings and was told that I should always use .equals.
However, I do not understand why this then works:
String y= "Mary";
String x= "Mary";
...
0
votes
2answers
46 views
Adding special characters to an array
I have a function that adds capitals, lowercase, and 0-9 to a character array and now i want to add special characters such as !@#$%^&*(). The format for my array goes like this:
for (char ch = ...
0
votes
2answers
69 views
Code refuses to display text in JTextArea
I created a JTextArea to show messages in multiple colours while the program is running.
I use NetBeans 8.0, and I added a JTextArea to the jFrame called "log" before writing the code.
First, I ...
0
votes
3answers
38 views
How to Read large size csv file and split each line to string array in java
i have GB of size csv file , i'am able to read this but when splitting it to an array then printing cause ArrayIndexOutOfBoundsException
this is my program
FileInputStream inputStream = null;
...