Tagged Questions
1
vote
3answers
38 views
For what are used the first 2 bytes in a java String
I send a string from java server to a C Client. In the client there are always 2 extra Bytes at the beginning of the String. I guess java use them to indicate the size of the string ?
I send the ...
0
votes
1answer
25 views
How can I convert a String of ascii values back to their String/Character values?
Given a String of numerical ascii values, how can I convert these back to their original characters to generate a String. I understand how this works, but I don't understand the regex that I would ...
0
votes
5answers
37 views
Spliting of String delimited by '[' and ']' [duplicate]
I have some sampel data written on a file. The data are in the following format -
[Peter Jackson] [UK] [United Kingdom] [London]....
I have to extract the information delimited by '[' and ']'. So ...
0
votes
7answers
44 views
Replace the last occurrence of a string in another string
Let's say I have a string
string myWord="AAAAA";
I want to replace "AA" with "BB", but only the last occurrence, like so:
"AAABB"
Neither string.replace() nor string.replaceFirst() would do the ...
-2
votes
1answer
32 views
Illegal Modifier for a Variable [duplicate]
I am currently building an app in Eclipse from a tutorial I found, but I have error in my code.
I have included the main activity file below (MainActivity.java):
package com.example.youdothemath;
...
-3
votes
0answers
32 views
Determining how Many types of Things are in an Array [duplicate]
I have a string array with various strings. What is the best way to find out how many different strings are present in this array. Note: some strings have spaces. The reason behind this question, is ...
0
votes
0answers
36 views
How to webscrape information with java
I've been trying to do a lot of research with webscraping. I'm trying to load the stats of different characters of the game I play into my program, and as there are over 150 of them I can't manually ...
-1
votes
4answers
41 views
How do I get the 5th word in a string? Java
Say I have a string of a text document and I want to save the 124th word of that string in another string how would I do this? I assume it counts each "word" as a string of text in between spaces ...
0
votes
4answers
20 views
Java String.getBytes( charsetName ) vs String.getBytes ( Charset object )
I need to encode a String to byte array using UTF-8 encoding. I am using Google guava, it has Charsets class already define Charset instance for UTF-8 encoding. I have 2 ways to do:
String.getBytes( ...
-2
votes
4answers
54 views
Java compare two strings and print line
I know this may be a really stupid question because my professor says I'm very close but I've tried so many different things. I've made an alarm clock and all that is left is to get the alarm option ...
0
votes
4answers
28 views
Converting XX:XX AM/PM to 24 Hour Clock
I have scoured google and I cannot find out how you can take a string: xx:xx AM/PM (ex. 3:30 PM) and change it so that it is now in 24 hours. So for ex. the previous time would be "15:30". I have ...
-1
votes
2answers
34 views
removing spaces in between the string
I am storing the result of list<Object[]> into a set as shown below..
String s ;
for (Object[] arr : ilist) {
String t = arr[2].toString();
Set<String> st = new ...
0
votes
1answer
39 views
Dynamic String Resource
[Hello], I have a problem.
Strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="num_e1_n1">%1$d</string>
</resources>
In the layout file :
...
0
votes
2answers
37 views
Multiplying string by a double
I have code like this:
double priceMulti = 1.2;
double price = Double.parseDouble(jTextField1.getText());
double date = 1980;
double random = Math.random()*20;
...
-3
votes
3answers
38 views
regular expression for string “ a123ab-lift(admin-hat)” [on hold]
I want to know the regex which confirms to
a123ab-lift(admin-hat)
My string can contain alphabets, numbers and characters " ( " , " ) " , " - "
0
votes
1answer
39 views
Slow byte[] to String constructor
I'm writing android java application (minSdkVersion 15) to get university timetable from php-site through api in json format. After decompressing content with InflaterInputStream i got a byte array in ...
0
votes
7answers
55 views
How to remove all occurrence of word in string Java
String test = "This is my learning of java language and this is interesting";
I want to pick first word of this string and remove all its occurences and result should be
String test = "is my ...
-3
votes
3answers
55 views
Java - making a regex that checks if some letters are in a string [on hold]
I am trying to make regex that will check if certain characters are in a string. For instance if I have the string "example" I want to be able to decide if the characters e, l and a are in the string. ...
-1
votes
1answer
38 views
String method is undefined for type string?
When I try to compile/read Eclipse, I come up with the following error:
"The method titleCase(String) is undefined for the type String"
Why is that?
Below is code:
public class Main {
String ...
2
votes
1answer
18 views
Enable Object Mapper writeValueAsString method to include null values
I have a JSON object which may contain a few null values.
I use ObjectMapper from com.fasterxml.jackson.databind to convert my JSON object as String.
private ObjectMapper mapper = new ObjectMapper();
...
0
votes
3answers
63 views
null string test is always true
I already saw a lot of similar posts, but none seems to be the same as this. I am testing if a string is null in my Java Android (2.2) app and whatever the string is, it is always true. Here is the ...
0
votes
1answer
27 views
Send String to OBDII
I want to send a String to an OBD2 Adapter, to read some information, for example the battery voltage. So I wrote this little program:
public class MainActivity extends Activity {
private ...
-4
votes
1answer
49 views
Get “day”, “week” and “month” as strings programmatically in java [on hold]
I want to use the following strings within my Java program :
"day"
"week"
"month"
But I don't want to hardcode these strings, rather I want to generate them programmatically using ...
0
votes
2answers
32 views
How can i write java reverse string program in ACM Library
I need a java program which reverse a string with using methods.
For example,
input:-"hellojava"
output:- "avajolleh"
-3
votes
2answers
41 views
How to find the index of closing parenthesis when the index of starting parenthesis and a String is given java program [on hold]
when the string is (A+b+(c+d)+(a))
Here the Index i: 0
Corresponding closing parenthesis: 14
0
votes
5answers
56 views
.replaceAll() method not working correctly
As a bit of background to the problem I load in a text file and then assign a phrase from that text file to become a randomPirateWord, I then change the letters into that text file to become **'s and ...
1
vote
4answers
42 views
String split and get perticular string
I have a string:
"cards_NNS may_MD be_VB worth_JJ hundreds_NNS a_DT report_NN"
Now i'm trying to get those words in a string array from given string which has _NNS and _NN and _JJ at the end of ...
0
votes
1answer
33 views
Can Java recognize variables placed in user input?
I'm new here. I'm wondering if Java can recognize variables input as a string.
Or, rather, would this work?
int Yn = 5;
System.out.println("please input the formula");
String x = ...
1
vote
6answers
43 views
Comparing two Time in Strings
I am trying to compare to strings:
Start Time: 10:00 End Time: 12:00
In actuality there is a start time array that contains my values and an end time array. In this case, it would be structured as ...
0
votes
2answers
24 views
Create a variable having name stored in a string variable
Let's say:
I have a Class Animal and I want to create an instance of that class by the name "bird".
"bird" is stored in a String.
How to do that?
String variable_name = "bird";
I want to use the ...
-3
votes
3answers
53 views
JAVA Split String into array [on hold]
i want to split a file. i have this in my file called data.txt:
ab
cd
ef
gh
ij
kl
mn
op
qr
so i have tried some coding. but when i tried to split them but it only read this:
ab
ef
ij
mn
qr
this ...
0
votes
1answer
28 views
Reversing a string recursively [duplicate]
Simple program that uses recursion to reverse a string. The only problem is that I get an error when I run the program.
import java.util.Scanner;
public class reverseString {
public static ...
0
votes
2answers
48 views
Split a string from example of other string collection
I'd like to build a collection of String (any complex data structure like a collection) that I can use, efficiently, as "example" to know where I can split a given string.
In example I had this String ...
0
votes
3answers
49 views
Regex doesnt work, how should it be formulated?
I Want to know if a String consists only of the same character except at the last index, it can be any other possible character except the character that's leading.
For Example: "FFFFFFFl" matches ...
0
votes
2answers
42 views
getText from JTextField in 1 class and place it on a label in the other
I have one class Names and it has a JTextField. I am trying to place getText from this textfield and save it in the variable nameString1. I then want the other class Game to call Names and place the ...
-2
votes
1answer
37 views
Java XML string literals abruptly terminated
I have some Java code that looks like this:
String xml = "<string>" + escapeXml(input) + "</string>";
protected String escapeXml(String input) {
return input.replaceAll("&", ...
-2
votes
1answer
45 views
String of number add together from an array java
I have a project to take a string of an unset amount of numbers together. In the project you have to convert the string to an array of numbers. Then start at the end of the array and add them ...
0
votes
1answer
26 views
Converting String of various symbols to Integer [duplicate]
Is it possible to convert strings like this +37068941556 to integers or longs or whatever numeric formats (in this case I would like to convert it to number 37068941556. Thanks in advance!
Stack ...
0
votes
2answers
21 views
String Message Staring with bullet-in needs to in the nextLine
I had string message,which contains message like below.
Here im trying to spilt the message when the line starts with number followed by .(full stop)
String str="1. Hi this is test 2. this is also ...
-1
votes
0answers
54 views
Java - getting a trienode (instances?) for iterator use
I have the code below and was wondering how can I access the current node through the iterator? meaning... how can i access the current node to iterate through. below in the methods i want to override ...
0
votes
6answers
62 views
How to read XML values using string methods of Java
I am looking for a way to search a string value from the following
<Test>
<Name>XYZ</Name>
<City>London</City>
</Test>
Note that tags are not going to be ...
1
vote
3answers
43 views
Should we keep symbols/special characters in StringConstants file?
I have read about it in a several places and also have been guided by my seniors to use String Constants in java. So I usually keep all logging messages and other required string stuff in my ...
0
votes
5answers
74 views
How to Store the String Value in Char array in java..?
I have to Store the String value in fixed char array, i tried but after storing the value char array size changed depends upon the String Value... Can Any one tell me how to fix that issue..
char[] ...
1
vote
4answers
81 views
How to handle special characters like “\n” in string reverse?
I have the following code to reverse a string, and I am considering to make test cases for it. I would like to know how to handle cases like when user input "\n", "\t" ?
private static String ...
1
vote
3answers
73 views
How to get characters to a string in Java?
I have a text file which contains the "Captured Network Packets' Headers" as hexadecimal values like this...
...
0
votes
3answers
36 views
Know If a String contains the same sequence in Java
OK first at all I want to know how many times I can find the world for example "lazy"
String string1= "The quick brown fox jumps over the lazy dog";
String string2= "The lazy brown fox jumps over the ...
0
votes
2answers
41 views
Java Method Confusion
In Java, when for example you say string1.compareTo(string2), how is the compareTo method accessing the string1. I see the method takes in the second string but how does it compare it to the first if ...
0
votes
3answers
42 views
Trying to get my java menu via methods to count properly
I am new to java, and have gotten THIS far with this simple menu program, getting the other parts to work(hence why I added them) but I am wondering exactly what I am doing wrong? I have tried ...
0
votes
0answers
72 views
Why is there always an String Index Out of Bounds Exception?
this program is supposed to convert something like
F_4(a,b;c,c';x,y)
to
\AppellFiv@{a}{b}{c}{c'}{x}{y}
I am using regex to match the first 5 groups and then I am using string methods to convert ...
0
votes
2answers
54 views
Checkerboard using arrays and object oriented programming
Driver Class:
//Objective: make a 10X10 Grid appear
//it should be a red and white or black and white
//checkerboard.
public Checkers()
{
con.setLayout(new ...