Tagged Questions
0
votes
4answers
82 views
Java - I can't replace char 'Á' with another char in String
Why this "Á" alphabet doesn't change? this code works on the other alphabet but Á.
public class Convert {
static String turkishCharacterConverter(String s) {
StringBuilder x = new ...
-7
votes
2answers
96 views
Java - How to write a code that Solve equation inside a String? [on hold]
How to make a string that can solve an equation, for example : if we have
String x = "a=3;b=4;c=a*b";
it must return "c=12" for an answer
-4
votes
4answers
74 views
Converting String to char?
I need to take a String and then work out how many times each letter appears in the string. I thought of maybe converting each letter of the string into an individual char. Is there any way to do ...
0
votes
2answers
35 views
separate html coded string and normal string
I want to split a single string containing normal text as well as html code into array of string. I tried to search on google but not found any suitable suggestion.
Consider the following string:
...
1
vote
6answers
53 views
Making a String containing the same character multiple times [duplicate]
How can I initialize a String with dynamic length in Java?
For example, I want to have a String consisting of n characters a, where n is a variable. Can I do that?
-1
votes
6answers
47 views
Splitting string data in java with white spaces
I have a string xyz a z. How to split it into xyz az. That is splitting the string into two parts taking first white space as the split point. Thanks
-4
votes
1answer
57 views
Split string using a string, split() function
I have the string
"Hello\nIm\nCory!"
How can I separate the string into String[] aLore?
I have used string.split()
using:
"\n", "\\n", "\\\n", "\\\\n"
All of those with plus' at the end, all ...
0
votes
4answers
41 views
Match 2 arraylists of questions and answers for a quiz game in java
I am making a quiz game in java with netbeans. I made an array list for all of my questions and another array list for my answers.I put both of them in order (like number one is what is the capital ...
0
votes
1answer
28 views
Complete String so that it matches regex
I have a string and a regex like the following:
fb
f(\w+)=\1
I would like to use these to generate:
fb=b
Is there any way to do this in Java? I can confirm that fb matches the f(\w+) using ...
-4
votes
2answers
44 views
How do I match a string to a user input using an if statement? (Java) [duplicate]
while (x == 1)
{
String[] riddles = new String[5] ;
riddles[0] = ("Hellowrite1") ;
riddles[1] = ("write2") ;
riddles[2] = ("write3") ;
riddles[3] = ...
0
votes
0answers
38 views
How to efficiently parse the data coming from the URL?
I need to parse the data which is coming from the URL and it looks like below -
haschanged=true
version=1
timestamp=1390561121310
DATACENTER=/pr/hello/plc
TotalNumberOfServers:4
...
0
votes
2answers
31 views
Reverse the string without changing white spaces in java
I'm working on reversing the string word by word and making sure that all the spaces, tabs and white spaces character etc. are not changed or removed. I have tried few solution using Java, but ending ...
1
vote
3answers
56 views
string as boolean
I'm making a spreadsheet in Java.
I'd like to make a copy of the Microsoft Excel function ISLOGICAL.
It checks whether a value is a logical value (TRUE or FALSE), and returns TRUE or FALSE.
All ...
0
votes
3answers
36 views
how to extract unknown names out of a string
I'm trying to make a Minecraft Server control panel, and I want to get a list of all online players, each username in it's own String. The way you get the users is typing /list and it returns a ...
0
votes
3answers
42 views
Get part of string ( from sth -> to sth )
Hi I have a question about how to get only part of given string :
String = "1. Name:Tom\tNumber:123";
in this case I would like to get only part with name ( "Tom" )
Is there is any solution to do ...
-3
votes
2answers
32 views
Problems with String Input [duplicate]
So, for some reason I'm having problems just USING a string input.
I don't know why. Maybe it's some incredibly stupid thing everyone knows, but I don't.
Here's the non-functioning code:
import ...
-1
votes
2answers
63 views
How to protect string from hacking
Can somebody tell me the changes should be made in String class API (we can't do that I know) so that following program should print "Earth" ? OR
How can we stop printing "Sun" ? How to stop hacking ...
0
votes
7answers
77 views
Java program to calculate the number of times each character appears in a string [duplicate]
I typed out this program to count the number of times each character appears in a String.
import java.util.Scanner;
public class fre {
public static void main(String[] args) {
Scanner s=new ...
0
votes
1answer
49 views
Java inputstream to string in case of a sentence
I have an external program (packaged in a jar) that I want to execute from another Java program, which I do using
Process proc = Runtime.getRuntime().exec(command)
This jar program now returns a ...
4
votes
3answers
101 views
How to remove multiple spaces and newlines in a string?
how to remove multiple spaces and newlines in a string? For example:
"This is
a string.
Something."
to
"This is
a string.
Something."
I'm using .trim() to strip whitespace ...
2
votes
1answer
60 views
Does compiler optimize String literals?
If i have a code:
String s="a";
s="b";
Note that there is no reference or use of s in between these two statements.
Will java compiler optimize this, ignore the first assignment and only store "b" ...
-1
votes
1answer
57 views
Custom String To Int function [on hold]
I am trying to make a function that converts strings to integers if the number contains only numbers (like parseInt). I am unable to do it. I need to use minimal built in library functions.
class ...
1
vote
7answers
99 views
Whats wrong with this replaceAll()?
The output I get is once the value of x is printed and remaining two println prints blank lines.
1.234.567,89
Process finished with exit code 0
What am I doing wrong?
public class Dummy {
...
0
votes
4answers
45 views
How to search an array of strings using wildcard
I'm trying to write a simple program that will search an array of string and output all the value which first sets of letters starts with what is in JTextfield
String[] words= {"apples", "applets", ...
1
vote
2answers
50 views
Concatenating ArrayList of Strings into a single String using StringBuilder
In Java, I'm trying to concatenate the Strings from an ArrayList (called filesToReport) into a single String, as I want to display all file names in a single error message in a dialog box if they do ...
-4
votes
5answers
88 views
Why do hash maps store values as “objects”?
Let's say I create a hash map and put a String in it. When I retrieve it, I have to cast it back as a String. Why can't I just pull it directly as a String? Sorry if the answer is obvious.
0
votes
5answers
64 views
Searching for an int inside a string user input
I am currently doing an assignment for class and I would like to know how to find an integer inside a string input. So far in the code I have created a way to exit the loop. Please don't give me code ...
4
votes
2answers
65 views
Recreate valueOf(double d) in Java's String class
I made an object, MyString. I can't figure out how to recreate valueOf(double d). I recreated valueOf for integers. Just to make it easier I limited the amount of decimal places to 8. How can I ...
-2
votes
2answers
48 views
How to convert a String[] into a set?
I did this:
Set<String> mySet = new TreeSet<String>();
String list = ("word,another,word2"); // actually this is much bigger
String[] wordArr = list.split(",");
mySet.addAll(wordArr);
...
-1
votes
5answers
65 views
How to replace one characters with two possible characters in a string
I want to know how to replace a string like "10?01?1" at '?' with 1 or 0. E.g., from string "1?0" -> "110" && "100". How to approach this problem? Recursive? Thanks.
EDIT with OP comment
...
0
votes
3answers
32 views
I don't know how to implement math.round() or any other solution to get ##.## in JTextField
I am displaying average in JTextField and I want to round it up to two decimal places to use my code above, to create BarChart using JFreeChart. I have seen many tutorials about that, but I don't know ...
2
votes
2answers
36 views
Finding the position of every one of a certain repeated char/substring in a string
While it's painfully obvious what I'm trying to do, I'd prefer not to be told how to come up with the end result even if the way I'm going about it is wrong (Hints will be appreciated though). ...
1
vote
1answer
58 views
Java: Find string within string
I'm trying to make some sort of system that would detect java syntax and highlight that code. However, I seem to be having trouble finding a string within a string.
This is what I have so far:
...
1
vote
2answers
34 views
ignore any non-alphabetic characters and capital letters from a string
prob a silly question but here goes:
I am looking to ignore any non-alphabetic characters and also capital letters from a string.
if (names[j].matches("[a-zA-Z]+")){
...
0
votes
0answers
44 views
Android: String class's equals method behave abruptly
I am reading a text file and from that I am inserting a value suppose ID=1s001(String) in the data base.
And I am again reading files but this time I want to make sure that I read files if the ID is ...
3
votes
1answer
31 views
Looking to replace a pattern of one string with a string that uses info from the pattern found?
It's tough for me to explain this problem without this example:
I'm looking to replace every instance of the string "switch('Pujols','Albert')" with the string "Albert Pujols", or the string ...
1
vote
2answers
48 views
Java string.match / string.replace does not match regex correctly
I have a string "123.0" and use "123.0".matches( "(\\.)?0*$" ) to check if it has any trailing zeros but it does not match. The same regexp matches string correctly @ http://regexpal.com/
How about ...
-5
votes
3answers
47 views
Converting String to Double in Java [on hold]
I am having an issue with an error I am getting when I compile my program. The only issue is that it needs a double and I have a String. I tried to cast it as a double (both variables), but that ...
0
votes
2answers
32 views
Convert the bytes of byte array to bits and store in Integer array
I have bytes in a byte array. I need to store the bit value of each byte in an integer array .
For example ,
the byte array is
byte HexToBin[] = {(byte)0x9A, (byte)0xFF,(byte) 0x05,(byte) 0x16};
...
1
vote
6answers
54 views
Create and call method that involves multiple System.out.println() and variables
I'm working on a little Java program that outputs a receipt to email students who registered for an AP exam at my school. The code looks like this.
// Create email text body for student who ...
3
votes
4answers
57 views
Size of a char in a byte array
As java doc states it:
char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).
But when I ...
0
votes
1answer
62 views
replacing a string using comparator in java
I was wondering if it is possible to compare recursively strings within a file using comparator and replace a string based on an element within it. I have some data:
331028124,24,7912,CF,1,1
...
0
votes
2answers
39 views
How to load Android strings array into ListView?
I'm trying to build my very first ListView in Android, and for this I'm building a custom ListAdapter. So I created a class called NotificationsAdapter which extends the BaseAdapter. Since I want to ...
2
votes
2answers
33 views
String to byte array and vice versa after having sent data over sockets
I've got a Client and a Server, both running on the same Computer (with Windows 7 OS). Programming language is java.
to send a message I use:
public static void sendMessage(Socket socket,String ...
0
votes
1answer
40 views
Getting substrings from constantly changing string
So I will cut down the explanation why I need it but will go straight to the point. My application is receiving an InputStream of type String. This message of InputString is placed into the ...
1
vote
1answer
54 views
How to extract sub-strings for a collection of text?
I extracted text from pdf document. .. I want to extract some particular fields in it using java..
The portion of text ..
US00RE44697E (i9) United States (12) Reissued Patent (10)
Patent ...
-4
votes
5answers
69 views
String.format doesn't have an effect on a String [duplicate]
In the following code timeToDisplay.format seems to have no effect on the timeToDisplay String. tw.setText(timeToDisplay) displays milliseconds instead of expected MM:SS. I've rebuilded the project ...
0
votes
2answers
61 views
How to split String into two parts? [duplicate]
I have the following String,
String Place = "3030XR Amsterdam";
I want to get it like
String postcode = "3030XR";
String City = "Amsterdam";
Can somebody help me.
1
vote
3answers
48 views
replaceAll, how to change letters
What would I need instead of "" to replace all alphabetical letters with * ?
public static void main(String[] args) {
String s = "Tere, TULNUKAS, 1234!";
String t = asenda(s); // "****, ...
1
vote
2answers
77 views
Searching for a List of Strings start with a particular String from a sorted ArrayList in java
Here I have an English wordlist : (For example )
account
angel
apple
application
black
...
And I want to search for strings which start with a particular String. For example : the result for ...