Tagged Questions
0
votes
2answers
15 views
Most efficient way of working with a String class property with a limited set of values
This is in an Android app, but the question might apply to Java/OOP in general as well.
In my app I have a class Job, which represents a job for the user to complete. One of its properties is status, ...
-1
votes
1answer
56 views
I'm getting a StringOutOfBoundsException in part of a java Project
else if (args.length == 5)
{
String firstyear = args[3];
String secondyear = args[4];
String datayear = temp[0];
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
...
1
vote
2answers
27 views
Finding the similarity of two String arrays
I apologize if there is a similar question asked before but only one I could find was How to find similar patterns in lists/arrays of strings
The problem is simple. There are two large arrays of ...
2
votes
6answers
76 views
Java: How to convert string into given custom format?
I want to write a java API which excepts two input parameters. First inputStr and second strFormat.
public String covertString(String inputStr, String strFormat)
{
// Need logic
}
For example,
...
0
votes
6answers
73 views
How to convert multiple character variables to one String?
I want to generate a fixed amount of random random characters, and then save those characters to a String variable. Here is the simple 'for' loop I have written so far:
String listChars = "";
...
1
vote
1answer
55 views
How to split a comma-delimited string into an array of empty strings
I want to split ",,," to a array of 4 "" using the String.split()
Here is my code:
String str = ",,,";
String[] tokens = str.split(",");
However, the result tokens were an an empty array: [], ...
0
votes
0answers
8 views
Avoiding syllabification on URLs
I'm trying to display a text like this:
"For more infomration please visi www.my-site.com"
For some resolutions/screens the text is displayed as:
|For more information please visit www.my- |
...
0
votes
2answers
28 views
Parse JSON string by escaping characters
I am receiving the below string from DB.
{
"MyDetails": {
"Type1": "A",
"Type2": "B",
"Type3": "C",
"Type4": "D",
"Type5": "E",
"Type6": "F",
...
1
vote
5answers
33 views
List files to String array and List files from FTP server
I'm writing apllication to synchronize two folders, remote and local, I have idea how doing that. But I'm beginner so, I have a function to listing files in local folder...
public static void ...
-1
votes
3answers
28 views
Reading data from keyboard to store in string array
String s[];
System.out.println("Enter loop value");
int t = s.nextInt();
for(int i=0;i<t;i++)
{
str[i]=s.nextLine();
}
while it reading it gives null pointer exception
0
votes
3answers
28 views
How to right declare a composite java JSON object from string?
i have this string which i'm using for testing of api:
{"limit":30, "offset":"0", "filters": [{"property":"vlc.vlc","operator":"=","value":"DEKU113829"}]}
I would like to create JSOn object for ...
0
votes
3answers
25 views
Read user input from Windows commandline print only from second letter - Java
When I run below lines in Windows command line it does not take the first letter. If I enter 22 it prints only '2'
private static String readInput() {
try {
BufferedReader br = new ...
0
votes
2answers
60 views
String vs StringBuffer in Java
After a long research , I got to know that String is immutable .String Buffer is more efficient than String if the program involves many computations.
But my question is slightly different from these ...
0
votes
1answer
32 views
how to preserve newline character in a string after converting to bytes?
String str[] = {"1000458551||A210171046D86F9F6EE21B66FE9B1441E20EC1DEF9654A2D092162591C01D26F||1||7707||0||"
+ "0||1002||1373569142000||HTC ...
1
vote
2answers
31 views
Java Split String Regex
Here is a String, I want to split the string such that the symbols and "words" are separate. For example:
String s = "/xyz/abc[bcd(text(),\"string\")]";
I want to have a String array like
...
0
votes
1answer
35 views
Java simple string print
Is there a more computationally-efficient way to write a simple constant string than this:
private void parseLabel(FileOutputStream asciiout) {
asciiout.write(new String("Label: ").getBytes());
}
...
0
votes
2answers
21 views
Struggling to create replace method for linked list
I have a linked list of names ie:(Mark, Matt, Marten, Brian, Matt) For my project I am trying to create a method where you replace one data with another and return the number of replacements.
Here ...
0
votes
3answers
31 views
what the objects of string class are final and is there any object that is final
In SCJP book i get a point by Kathy Sierra that their is no final object in java. There are only final reference variable in java.
But i think objects of string class are final. As once initialized ...
0
votes
5answers
41 views
How to print out the number of capital letters in a string - java
So I have this program I need to write. I'm, supposed to get an input string from a user and then print out how many capital letters and how many lowercased letters are in the string. I've looked ...
1
vote
5answers
43 views
Convert word into an array of 2 letters
I'm trying to figure out how to convert a String representing a word into an array of 2 letter elements.
For instance, I have word: believe
Then, I convert it to array of 2 letters.
The array what ...
0
votes
4answers
52 views
Convert a string into a variable in java
I am building a DAQ in a Java based Platform called KMax. This platform, has a design interface to use objects like histograms. Each histogram has a name, which is declared on the design interface.
...
0
votes
5answers
82 views
String to char[] without String methods
I am practicing for interviews and I am given a question to create the String method indexOf without the use of string methods. My first thought was to process the String into a char[] but I am not ...
0
votes
3answers
41 views
Remove unneccessary information from a link? [on hold]
So I have a site where a user enters a link (which may or may not be from amazon). There's a problem with amazon links though since they add quite a lot of unneccessary information to the URL.
For ...
0
votes
1answer
36 views
android app keeps crashing “unfortunately,Calculator Has stopped”
I keep getting an error log when I try to run the following code
There is the error message:
03-11 16:00:08.350: E/AndroidRuntime(842): FATAL EXCEPTION: main
03-11 16:00:08.350: ...
0
votes
1answer
27 views
android convert EditText input string to its hex equivalent
Hello I would like my application to allow a user to input a number 1 to 16, press a button and then have the input number's hex equivalent shown on screen as a toast message and also store is hex in ...
0
votes
4answers
41 views
Checking if JTextField contains only specific allowed characters
I have a JFormattedTextField where I want only alphanumeric characters to be inserted. I am trying to use this code to launch a JDialog when the user types a non-allowed character, and in case ...
5
votes
5answers
113 views
Java string replacing
I have a string like that ($ character is always surrounded with other characters):
a$b
c$d
e$f
I want my string method to put a \ in front of $ and remove newlines:
a\$bc\$de\$f
I tried this ...
0
votes
3answers
38 views
Java compare string with hash and without hash
I have a String that contains hash (it was automatically generated by third party program) and I have another String that do not contain hash and I need to compare to the first String.
Method ...
0
votes
1answer
45 views
How to resolve the error in the following code
I have written this code to generate the bit stream corresponding to string a and then invert
specific bits in a bit stream.the variable cc gets an integer value in the processing before the code ...
5
votes
5answers
68 views
java produces same hashcode for different strings
I understand that this seems to be already discussed and the answer is yes but quite unlikely (javas Hashcode can produce same hashcode for different strings?). However it does happen in my ...
0
votes
1answer
5 views
append currentChar to the end of cryptText, saving the result back to cryptText
package edu.westga.secretcode;
import java.util.Scanner;
/**
* Creates the secret code class.
*
* @author Stephen Roland
*
*/
public class SecretCode {
/**
* Perform the ROT13 ...
0
votes
1answer
52 views
Issue with java.lang.NumberFormatException
I have a variable which contains some parameters which affect a created weka model. I want to change automatically the parameters values. I ve got the following:
String c [] ={"1.0", "10.0", "20.0", ...
0
votes
2answers
43 views
How to transfer a string to a void from a separate class (Java)…?
Okay, here's this problem I have in my java class. Upon searching, I didn't find any results, so.
I have this string value for x, y and z positions in one of my classes named 'statpedia'...
public ...
-1
votes
3answers
47 views
Changes to string still in effect after loop ends in Java
So I have this script:
class input {
public static void main (String[] args){
String hexa;
hexa = ...
0
votes
2answers
27 views
Enum <-> String comparison in JAVA
I want to compare a String with an Enum. I know how to do the comparison properly but i don't understand exactly why. My following example shows my issue:
enum Foo{
TEST1
}
String likeEnumTest1 ...
0
votes
4answers
56 views
Get the Smallest Matching String from a Long String
Suppose I have a String
interpreter, interprete, interpret
now what i want to do is to get the smallest matching string from the above string that must be:
interpret
Is it possible using ...
0
votes
0answers
31 views
java - String args gets trimmed/linearized while executing jar file using Runtime/ProcessBuilder
I am executing a jar file in my test program : passing arg1 and arg2 as parameters.
arg2 is a string which is created by reading a PDF File, converting the file to byte array and byte array to String ...
4
votes
3answers
54 views
StackOverflow when checking if one string is contained in another
I currently have a method that is supposed to take two strings and then check if one string exists as a substring in other. It doesn't check both ways so the way in which I pass my strings to the ...
0
votes
1answer
16 views
How to make Java GUI settext recognize new lines for a 2 dimensional array input
I have a char[xSize][ySize] being sent to my GUI. The GUI prints the long string as one long line without recognizing the new lines in it. What method or code could I use?
The code I currently use is:
...
0
votes
3answers
23 views
Remove Specified Character From String
In my Text Rendering system for my game, I've implemented support for coloured words.
So, if I want to render a sentence with the first word in red, and the other words in white, I can do something ...
0
votes
0answers
27 views
Java mesageSource best practice
I'm creating a vaadin view class wрich has the messages in properties which is the expected, and I'm using those values to set the labels messages, buttons, etc.
I know that a good practice should be ...
0
votes
5answers
51 views
“main” java.lang.StringIndexOutOfBoundsException: String index out of range: 17
Exception in thread "main" `java.lang.StringIndexOutOfBoundsException: String index out of range: 17` at java.lang.String.charAt(String.java:658)
at Stadium.<init>(Stadium.java:104)
...
1
vote
2answers
52 views
Java command Storage
Yes, this question is for a bot, but it requires little knowledge of bots. So please, don't be put off by that.
This question may seem similar to other PircBot questions, but bear with me, it isn't.
...
2
votes
1answer
38 views
Why is this not converting all instances?
I do not know why this code is not converting all instances of 'm' to 'M' and instances of 'M' to 'm'. For example, it should be converting to:
Report 98-17, Faculty of Technical matheMatics and ...
-5
votes
2answers
37 views
Switch statement on String [on hold]
i have a method as follows to return string with switch-statement.
public String getsplid(String unit) {
String txt = null;
switch (unit) {
case "AA":
txt = "00";
...
1
vote
3answers
40 views
How to split a character without removing it (regex) [duplicate]
I want to split a string at a certain point, but keep the character I'm splitting it at. For example:
Input:
a:b
Output:
a
:
b
Is there anyway I can use this with Java's split() method?
Thanks :)
0
votes
5answers
35 views
Method not working as Planned?
Scanner adjectives = new Scanner(new File("adjectives.txt"));
String[] adjectiveArray;
adjectiveArray = new String[25];
int counter = 0;
while (counter<25)
{
...
0
votes
2answers
45 views
Sorting Strings in an Array by Char
I'm trying to sort a list of strings in array into alphabetical order without using the sort method.
public static String[] sortedAdjectives(String[] original)
{
String[] sortedArray;
int ...
1
vote
1answer
14 views
Can't detect 2 digit numbers when converting from RPN to Infix
i am trying to implement a java method which accepts an input in RPN (Reverse Polish Notation) and through use of a stack converts it into an infix notation and calculates it. I have built the stack ...
0
votes
1answer
27 views
Time complexity of String matching and Integer Matching
How different are string matching and integer matching in terms of time complexity?
I'm asking this especially in relation to Rabin Karp algorithm. Why is it faster to compute a hash code for every ...