0
votes
1answer
25 views

How do I separate strings with a comma and a space without having them being put before it?

Beginner programmer here. I have to append strings of file names together and have come up with the following methods: class ConsLoItem implements ILoItem { Item first; ILoItem rest; ...
0
votes
3answers
16 views

Convert UTF-8 string to alphanumeric string without information loss

I want to use Jake Wharton's DiskLruCache for Android to cache CouchDb documents on disk. CouchDb ids are just any JSON String, so could look Sömething/Like/Thís. However, the library's docs state ...
3
votes
0answers
32 views

Drawing strings inscribed in a circle

I am aware of Java's drawString(String str, int x, int y) method; however, sometimes all I want is to label a circle with an appropriate string in the middle of it, given a font size (either in pts or ...
2
votes
2answers
61 views

Optimizing String manupulation code

I am trying to all possible child domains from a given host. I have written following code. It works but my only worry is performance. Is it required to optimize this code further: package ...
2
votes
2answers
33 views

Capturing spaces with Scanner?

I have a series of questions being asked to create a deck of flash cards. So far, I can gather questions and answers, provided the questions don't have spaces. If a question does have spaces, the ...
0
votes
0answers
8 views

Can not add user to a group with Ldap in Java

I am new with using Ldap API for Java and I want to add a user to a group but I'm failing all the time. I am using this code for adding specific user to a specific group: private void ...
5
votes
3answers
48 views

String permutation with recursion

I am a java beginner and trying to do a string permutation practice from java programming book. I am defining two method: public static void displayPermutation(String s) public static void ...
0
votes
1answer
44 views

java program - database output not showing backslashes

How can I replace the single backslashes "\"in the string filepath with either double backslashes "\" or a single slash "/" ? I need it so that i can execute the desktop method in java properly here ...
5
votes
3answers
110 views

Why constant strings use intern()?

I'm aware about string pool in JVM and difference between literals and string objects. I know that literals are automatically interned, but what is the purpose of this line then: public static final ...
-3
votes
2answers
64 views

Why does this loop reverses a String in Java

I'm trying to remove whitespaces in a given string, and, while I've achieved this, the returned String appears reversed. Can anyone please explain why? public String removeSpaces(String cadena) { ...
1
vote
3answers
43 views

Java mutable “String” with efficient per-char operations: toCharArray() or getBytes()?

I want to do some efficient per-character replacements in a java String, which is the better approach, to work with .toCharArray() or .getBytes() ? Example code: // big loop { String s = ...
1
vote
1answer
31 views

Annotation parameter: explicit vs. implicit String array

Why does the second Test in my scenario has the syntax error The value for annotation attribute SuppressWarnings.value must be an array initializer on the SuppressWarnings line? public class ...
-6
votes
1answer
62 views

String split Java by newline character [on hold]

I have a string as follow: String s = "Dog\nBarks\n\nCat\nMeows\n\nLion\nRoars\n\nWolf\nHowls\n\n"; I want to split it into 4 different string using \n\n as delimiter. Desired result: Dog\nBarks ...
-1
votes
2answers
66 views

Interesting thing happening when I take a number, multiply it by 10, and then add 1 [duplicate]

static int fn = 0; static int sn = 0; static boolean running = false; public static void run() { while (running == true) { fn = numbers[0]; sn = numbers[1]; ...
4
votes
4answers
55 views

ArrayList<Byte> vs String in Java

I am implementing the LZW algorithm. I have implemented it for strings and text files successfully and am currently modifying my code to work with binary files, such as images or executables (since I ...
0
votes
5answers
43 views

Making a loop while inserting characters into a String?

I was making a new code where my objective was to make whatever key you press make my little "truck" go forward. I was trying to do this by adding spaces to my string, which was my truck. String ...
0
votes
4answers
49 views

checking a string for null in java

I have this: String object = ""; try { object = data.getString("url"); System.out.println("Url Object:" + object); } catch (JSONException e) { e.printStackTrace(); } ...
1
vote
1answer
39 views

JSONArray throwing out of memory exception in android

In my app I sync some data at the end of day to the app server.For this I wrap all my data as a JSONArray of JSONObjects.The data mainly includes about 50 pictures each with a size of approx ...
0
votes
4answers
42 views

How to get the specific part of a string based on condition?

I have a requirement to get the substring of a string based on a condition. String str = "ABC::abcdefgh||XYZ::xyz"; If input is "ABC", check if it contains in str and if it presents then it should ...
0
votes
6answers
49 views

How to get a substring of a certain character followed by a number?

In Java, how would I get a substring of a certain character followed by a number? The string looks like this: To be, or not to be. (That is the question.) (243) I want the substring up until the ...
1
vote
3answers
44 views

How to generate a random numeric string + random char string and combine?

What I'm trying to do is to generate a random string of numbers E.G 2645237 and one char in a string in the range of A-Z E.G. W and combine the two strings to make 2645237W. I can generate a random ...
1
vote
3answers
74 views

Counting occurrences of string in an arraylist using case-insensitive comparison

I have to count the occurrences of each String in an ArrayList that includes Strings and ints. Right now I have to ignore the int variable that corresponds to the quantity of every item and just count ...
1
vote
2answers
52 views

String.split() using multiple character delimeter

I have a String saved in the database like this: 01/01/2014$%^&02/01/2014 I am using the split() java method. Here is my code: String value = database.getValue(); // this returns the value ...
-7
votes
1answer
50 views

sort ArrayList<String> using strin length [duplicate]

I tried searching for this in here and got answers, but, i think people here are forgetting the point that some ask because they have no idea how to do it. developers here just give a piece of code ...
0
votes
2answers
56 views

Why Don't These Strings Match? [duplicate]

I'm getting the user input like so: Scanner keyboard = new Scanner(System.in); String input = keyboard.nextLine(); When I compare it like this if(input == "abc"){ System.out.println("Match!"); ...
0
votes
1answer
29 views

Solving expressions in an array

JMelnik posted a great program here : Random math questions generator for Android I am attempting to teach myself java, so I took the source code and I am attempting to wrap my head around ...
-1
votes
0answers
14 views

failed stopword removal process, stopword in asset folder

I want to make the process of stopword removal from textview in my activity, stopword words I was put in the txt file in assets folder. but when i run the program, not a process at all stopwords, ...
6
votes
4answers
156 views

Where is \n located in a String?

Lets say we have a String: (with the variable name 'string') This is the first line And this is the second I only skipped one line within that String. If I were to split that into separate words ...
0
votes
3answers
53 views

Two variables initialization at once in for loop

I want to write a code for reversing of string. I know there are many methods for it. However, I want to try using Arrays. But I am having problem with the output. Following is my code: package ...
-1
votes
4answers
52 views

Unable to compare Char / String? [duplicate]

What I want to do is simply read a input (Char/String , preferably char), its a single char and then print some outputs based on the inputs. My problems faced is that, if i convert my input 'choice' ...
3
votes
2answers
57 views

asterisk letter wrong alignment java

When I view list item with a text aligned to right in Arabic language, wrong formatting occurs. In all Arabic statements, it works fine. [arWord].25.3 but only when the text is * it looks like this. ...
-4
votes
0answers
36 views

Truncate string or wordwrap in Java?

Write a method that reads a text file and wraps only whole words, never chopping a word in half. Assume that a word is any whitespace-separated token and that all words are under 60 characters in ...
1
vote
1answer
57 views

Returning 2 different strings

Is it possible to do what this code is trying to do (Current code format causes an error) public String fileStream(){ Object[] yesNo = {"Yes", "No",}; int nn = ...
0
votes
1answer
17 views

Losing data through piped streams in java

I'm doing a lab work for my parallel and concurrent programming class in Java. For now, I'm trying to use piped streams to communicate between threads. I'm using PipedWriter and PipedReader from the ...
0
votes
1answer
34 views

Searching SortedSet<String>

i'm working on a word game, one of its methods is a scramble method, it should take String s then shuffle it using Collections.shuffle(ListOfSChars); and check if scramble is within SortedSet ...
2
votes
5answers
58 views

initialize string dynamically in java

I want to initialize a string as follows: public int function ( int count ) { String s_new = "88888... 'count' number of 8's " <-- How to do this //Other code } Currently I'm not sure ...
-2
votes
0answers
43 views

Recursive string array in Java? [on hold]

I am looking for a sorting algorithm in Java that is recursive. I've been searching for a while now and I can't find anything that will sort a array of Strings. I have been looking at quicksort but ...
2
votes
3answers
49 views

How can I replace all occurrences of the division sign with a slash in Java?

I would like to replace all division signs and multiplication signs in a string with the characters / and *. How can I do that? I already tried it with this method but it does not work. public ...
0
votes
4answers
37 views

Regular Expressions - Using Regex to search for a specific string within another string

I want to search a string for an identifier. The identifier can 4 have variations REF964758362562 REF964-758362-562 964758362562 964-758362-562 The identifier can be located anywhere in a string or ...
0
votes
2answers
34 views

String regex with groups

I try to use the String.replaceAll method for replacing a String like <br> with <br/>. Because <br> can be something more complicated like <br style="">, I need the same regex ...
1
vote
2answers
77 views

How to parse a sine function?

I have String input with a sin (b(x-c)) + d as its format. What is the delimiter expression I should use to split it so that I can use Integer.parse to obtain the numerical values for a, b, c and d? ...
0
votes
2answers
70 views

need help on java programming

I have a homework and after struggling a lot i didn't succeed to solve it so i ask it here , the question is : we have list of students and their grades in a string.the string contain Student number , ...
0
votes
2answers
60 views

Strings - Number guessing game [on hold]

This is a game that generates a random 4 digit number and then lets the user input 5 chances to guess the game and returns a hint as to how many numbers were in the correct place and how many matched ...
0
votes
2answers
61 views

Java String automatically assigned null value [duplicate]

In the code below, in the first iteration of the first for loop, boxes[a] is automatically assigned a null value. The remainder of the iterations are fine (user input is accepted). Only the first ...
1
vote
2answers
50 views

String search with “?” as a joker?

I have an ArrayList of strings and I want to perform a search method on them. So far I only have this: public void searchNote(String searchCertainNote) { for (String note: notes) { if ...
-1
votes
2answers
34 views

Scanning user input text

I´ve been trying to get user input as a text and then outputting one of 2 answers depending on the input. This is how far I´ve managed to get with the help of Google: import java.util.*; public class ...
0
votes
4answers
88 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 ...
2
votes
7answers
190 views

Fast Lookup of Java

I currently have a String array that I need to search many times for an exact match. What would be the best data structure to use? Example - String array with elements cat dog squirrel raccoon ...
3
votes
3answers
15k views

Java: Getting a substring from a string starting after a particular character

I have a string: /abc/def/ghfj.doc I would like to extract ghfj.doc from this this, ie, the substring after the last "/" or first "/" from right. Could someone please provide some help?
20
votes
7answers
53k views

Using Enum values as String literals

What is the best way to use the values stored in an Enum as String literals? For example: public enum Modes { some-really-long-string, mode2, mode3 } Then later I could use Mode.mode1 ...

15 30 50 per page