Tagged Questions
0
votes
2answers
27 views
Regex to Split String is not working well for “[,,.\\s]” in Java
I hope to split a String into groups by"," or","(Chinese comma) or "." or any blank char(like white space or "\n").
I am new to regex.
I write the below test case:
String str2="word1 , ...
0
votes
1answer
24 views
Split numbers and letters in an Alphanumeric String
I need to split an Alphanumeric String and split the alphabets and numbers. For example, if I have a string like: "Room 502", I need to get the number 502 as a separate string to "Room". Could someone ...
1
vote
0answers
33 views
How can I convert a string to an object reference? [duplicate]
The issue I am having is I am trying to write an app that has the user put in their customer number, and that string then calls the appropriate instance of the object.
public static void ...
2
votes
2answers
41 views
How to escape slashes that are to be part of the string?
Im having difficulty finding a way to escape these quotes,
String key = StringUtils.substringBetween(html, "class=\"category_keyword\"", ">");
Specifically this part:
...
1
vote
1answer
35 views
Displaying an Integer as an output of Xs
So, I'm pretty new to the Java language and am having problem with a homework assignment. I need to take a console input from the user and display the number as a line of Xs. (i.e. "Cars sold by Pam > ...
-8
votes
2answers
38 views
string copyValueOf in java [on hold]
public class stackcall
{
public static void main(String args[])
{
string a = new string();
System.out.println(a.str1);
}
}
class string
{
static char str[] = ...
2
votes
1answer
39 views
Method Local Strings Memory Allocation?
I understand how String pool and intern() method works in java.Here is a brief intro
String.intern() in Java 6
In those good old days all interned strings were stored in the PermGen
– the ...
-4
votes
2answers
22 views
Extract matching words from files
I have several text files and a data set of several words. I have to match for every text file what are the words that are matching. How can it be achieved?
I initially started with tokenizing each ...
0
votes
1answer
71 views
String naming convention in java
I am currently trying to make a naming convention. The idea behind this is parsing.
Lets say I obtain an xml doc. Everything can be used once, but these 2 in the code below can be submitted several ...
1
vote
1answer
42 views
Converting from different arrays to standard form
I would prefer a small sample code that i could remake into a larger scale of this question(s), or a link to a specific question/tutorial regarding these question(s).
What i have done is i've stored ...
0
votes
4answers
75 views
Need advice for my java if-statement
i wanna be able to use an if-statment like this:
int price = 60;
if (pizza.equals("string1","string2","string3")) {
int price2 = 10;
System.out.println("You want " + pizza + " and it will ...
0
votes
4answers
31 views
Android: format string and add bold style
I have a string in my resource:
<string name="region"><b>Region:</b> %1$s</string>
I am trying to set this text to a textview:
...
-2
votes
3answers
48 views
In Java, what's the best way to get numbers from a one-line String? [on hold]
For example:
input:
14 5 1
What's the best way to get these three values into three int variables?
Also, does it make any difference if we were dealing with double values?
0
votes
1answer
29 views
Converting an String array into char array to compare it with another text file [on hold]
Given two files
random_letters.txt
AABBBBB
FLOWERS
BACKGFD
TOBEACH
dictionary.txt
flowers
to
beach
back
I need to check each combination of the random_letters with dictionary to see if there is ...
-2
votes
0answers
20 views
Best way to automatically build Querys in java
I'm using Java and SQLite to create a program that handles multiple tables and I'm trying to build a code that passes data to each table. All the tables have different content, more or less columns, ...
1
vote
2answers
44 views
Groovy String adding quote to begining of string instead of end
public ArrayList<String> findLocationOfXMLDocumentsWithSkills(ArrayList<String> skillsToFind){
TreeMap<Integer, ArrayList<String>> fileLocationToNumberOfHits = new ...
0
votes
1answer
52 views
Using Grep in Java Code
I have two identical arrays, Noun and Noun1, and want to find and extract the line that contains the combination of words (parliamenr reviews). I want to use grep command in linux and I wrote the ...
1
vote
1answer
45 views
Will the String passed from outside the java application be saved in String pool?
I read many answers but none of them really answers my question exactly.
If I've a java service running on some port and a client connects to it and calls a method like:
String data = ...
-1
votes
4answers
52 views
Preventing a String from getting integer values in Java
Is there a possible way to do that?
e.g In my application form a have a field for the user's name which is a String. But how can I disallow the user from giving for example "L3bron James" instead of ...
1
vote
4answers
35 views
Get substring according to occurrence, reg exp java
Good day everyone! I wonder if anyone could help me out.
I have a string -2.100 CM 1.000 CM 1.025 CM
The problem is getting the values before CM, e.g. -2.1, 1.0, 1.025
Pattern pattern = ...
0
votes
2answers
33 views
Converting a line of words from lower case to upper case
I would like to convert a line of words, including punctuation and spaces, from lower case to upper case. My method to deal with the question is to firstly store the sentence in String form, then ...
1
vote
4answers
63 views
How to get (split) filenames from string in java?
I have a string that contains file names like:
"file1.txt file2.jpg tricky file name.txt other tricky filenames containing áéíőéáóó.gif"
How can I get the file names, one by one?
I am looking for ...
0
votes
5answers
52 views
Comparing the reverse word of a string to the original string Java
This is the solution I came up with:
public void reverse(String str1, String str2){
int j = str2.length() - 1;
if(str1.length() != str2.length())
{
return false;
}
else
{
for(int i = ...
0
votes
2answers
26 views
Produce variable size digits without leading zeros with Java String format
If you try this code:
public class StringFormat {
public void printIt() {
String pattern = "%%s%%0%dd%%s"; // <-- THIS SHOULD BE FIXED
String arrayName = "aaaa[12]";
...
4
votes
2answers
69 views
What is the difference in converting string buffer to string using .toString(), String.valueOf() and + “ ”
What is the main difference in conversion of StringBuffer to String for the following three cases :
Case 1 : Using toString()
StringBuffer sb = new StringBuffer("Welcome");
String st = ...
-2
votes
0answers
24 views
DOSBox commands through Java Program-word gets removed
String run="c:\\Program Files\DOSBox-0.74\dosbox.exe dosbox -c mount c c:\games";
The word c c:\games gets removed. Please advise how do I prevent this? Should I use a literal to insert the spaces in ...
0
votes
3answers
32 views
Adding elements to a list of strings in java [duplicate]
I and more used to how things are done in C# than how things are done in java. The following lines are in java:
List <String> cIDs = null;
cIDs.add("something");
This shows a warning in ...
0
votes
2answers
49 views
Converting a String representing a mathemetical expression into an array
I want to convert a String such as 1+40.2+(2) into a String array [1, +, 40.2, +, (, 2, )] in order to use it as a parameter for a Shunting Yard algorithm in my Calculator class.
The input will be ...
0
votes
2answers
37 views
How do I make a program that takes a string but disallows numbers?
I'm developing a game and it asks for a username at the start which will then be added to a txt file and saved. But the problem is that the user can write absolutely anything. Their usernames are ...
0
votes
1answer
37 views
Convert protobuf message to string in Java for persistency
I am working on a project which stores all data in key/value pairs. Both the key and value are strings. Changing this is beyond the current scope. Each data concept is represented by a protobuf ...
0
votes
1answer
50 views
How to Print String object Line by Line
I have the following code to convert text file to xml.:-
**
public static void main (String args[]) {
new ToXML().doit();
}
public void doit () {
try{
in = new BufferedReader(new ...
0
votes
1answer
54 views
Empty String to indicate object state
From time to time I bump into code like this:
...
private final JButton addButton = new JButton(...);
private String warningMsg = "";
private void update(){
addButton.setEnabled(warningMsg != ...
-2
votes
1answer
26 views
Getting text file content to string [duplicate]
I have a one question. How can I get all text file content to String format?
Please show me that code. Thank you.
P.S Search didin't help.
Sorry for my bad English.
-6
votes
1answer
49 views
How to store a string array inside a string in java
I have a String in java
String s = "i am {0} in IT {1} industry";
and another string array is
String[] s1={"Java developer","software"};
I need to put the data of s1 inside s in place of a[0] ...
1
vote
6answers
66 views
How to insert newLine Between Text
I have created an object(new1) which contains the following text
E-Mail: [email protected] Number (PNR):H246FY
The output should be displayed in two seperate line as follow:
E-Mail: ...
0
votes
7answers
79 views
str.contains in Java
I am having 2 lists
allWords [book, pen, pencil]
subsetString [book pen , book pencil , pen pencil ]
I am expecting my output as
book pen => pencil
book pencil => pen
pen pencil ...
0
votes
1answer
52 views
Java Output double in Scientific Notation
I got a weird case. I tried two different method to output the double number in Java. Let the result be a double number. The first one is :
DecimalFormat resFormat = new DecimalFormat("0.00E00f\n");
...
0
votes
2answers
26 views
How do i replace a double line with a single line in a string in Android?
I have a string:
This is a test sentence 1.
This is a test sentence 2.
This is a test sentence 3.
This is a test sentence 4.
This is a test sentence 5.
I would like to replace the double ...
0
votes
1answer
17 views
How to convert SOAPBody to String
I want to convert SOAPBody to String. What is the best way to do it?
Should i first convert it to xml and then convert it into String or we can jsut convert it into String.
1
vote
1answer
29 views
Format specific section of String
I have a String: a%sb%sc%s. I need to format b before I format a or c, but I'm not sure how or even if I can specify only to format b while keeping the rest of the String unformatted.
In other ...
0
votes
5answers
43 views
When do I need to initialize a String?
Going through some switch command tutorials from various sources. I am trying to create a small program based on this SwitchDemo tutorial ( I have removed some repeated code to save space):
public ...
0
votes
5answers
73 views
How JVM allocates memory for String in java?
I have a scenario like this -
String s = "abc", t="abc"; //LINE 1
System.out.println(s==t); // definitely it would return true; //LINE 2
s=s+"d"; t=t+"d"; //LINE 3
System.out.println(s==t); // ...
-6
votes
6answers
87 views
JAVA string how can i implement the length method
My roommate's teacher gave them a assignment to implement string length method in JAVA?
we have thought out two ways.
Check the element,and when get the out of bounds exception,it means the end of ...
0
votes
0answers
33 views
String char-set in Java and Oracle DB
Hi i am using Oracle DB to store string on Varchar2 column,
with using eclipselink my code is here,
pdescription = new String(this.description.getBytes("ISO-8859-9"));
sometimes its ok but, ...
0
votes
4answers
65 views
Splitting String with wildcard
I have a variable String which contains values i need and splitters. The problem is, the length of the string is variable and the type of splitters as well. They arrive through XML-file.
A string ...
0
votes
5answers
97 views
What is difference between mutable and immutable String in java
As per my knowledge,
a mutable string can be changed, and
an immutable string cannot be changed.
Here I want to change the value of String like this,
String str="Good";
str=str+" Morning";
and ...
-1
votes
2answers
42 views
How to convert hex value to Special Char( in Unicode )?
In my previous question, I asked about conversion of Special Chars to Hex.
Hex value of "ㅂ" is "e38582"
Now I've got hex value in String.
String hex = "e38582";
How to convert this hex ...
-1
votes
2answers
26 views
Taking parts of a sentence in String using Regex
I have this sentences which I want to manipulate and take its information:
Hello. Yr data allocation based on Fair Usage
Policy is 10,240.0MB. Yr current usage is 2,858.6MB. Balance:
...
-1
votes
2answers
22 views
Java TextField getText() give me a string that I can't compare [duplicate]
I would like to control when a string form my textfield is empty or not. Here there's the code with a simple Swing interface:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public ...
0
votes
3answers
44 views
Insert/Add/Append option in StringUtils in Java
Is it possble to convert a string in a/b format to double in Java?
Ex: str = "4/5";
Can I parse this and get float/double value?
I used parseDouble, but did not work and it expects something like ...