In Java, I have a String and I want to encode it as a byte array (in UTF8, or some other encoding). Alternately, I have a byte array (in some known ... |
I am looking for a way to convert a long string (from a dump), that represents hex values into a byte array.
I couldn't have phrased it better than the person that ... |
I need to see if a string value matches with an object value, but why won't this work?
public int countPacks(String flavour) {
int counter = 0;
...
|
What is the best way to print the cells of a String[][] array as a right-justified table? For example, the input
{ { "x", "xxx" }, { "yyy", "y" }, { "zz", ...
|
I'm working with some example java code for making md5 hashes. One part converts the results from bytes to a string of hex digits:
byte messageDigest[] = algorithm.digest(); ...
|
Maybe there is a method that does this that I don't know about - I doubt it though - but I'm trying to convert an array of strings to an array ... |
EDIT: ah, there it is! Problem solved, thank you! (Bug was elsewhere, not in the copy function.)
I'm working with a program that uses two-dimensional arrays of Strings (probably not that ... |
|
Since its possibly one of the most widely used methods of the Java language, why does it have to accept an array of Strings and doesn't work without it? For example, ... |
This is my assignment:
link
Here are my questions:
- How can I fix this error:
Exception in thread "main" java.lang.NumberFormatException: empty String
... |
I need to store in a constant class 4 letter of a code. I can do:
static final String CODE_LETTERS = "TRWAG";
or
static final char[] CODE_LETTERS = {'T', 'R', 'W', 'A', 'G'};
After, I ... |
I'm trying to debug something and I'm wondering if the following code could ever return true
public boolean impossible(byte[] myBytes) {
if (myBytes.length == 0)
return false;
...
|
I am writing a decryption class (AES/CBC/PKCS7Padding) where the encrypted data is coming from C#. I want to take the following string (which is base64 encoded):
usiTyri3/gPJJ0F6Kj9qYL0w/zXiUAEcslUH6/zVIjs=
and convert it to a byte ... |
I have a byte array initialised like this:
public static byte[] tmpIV = {0x43, (byte)0x6d, 0x22, (byte)0x9a, 0x22,
...
|
I'm pretty new at this, and this is probably a pretty obvious answer. In my csv script, i'm trying to figure out how to read a csv file using the ... |
I come from a php background and in php, there is an array_size() function which tells you how many elements in the array are used. Is there a similar method ... |
I use the following code to convert an object array to a string array :
Object Object_Array[]=new Object[100];
// ... get values in the Object_Array
String String_Array[]=new String[Object_Array.length];
for (int i=0;i<String_Array.length;i++) String_Array[i]=Object_Array[i].toString();
But I wonder if ... |
I recently started looking at MD5 hashing (in Java) and while I've found algorithms and methods to help me accomplish that, I'm left wondering how it actually works.
For one, I found ... |
I use the following code try to create an array of string vectors, I hope to have an array of 3 items, each item is a string vector :
Vector<String> Result_Vector_Array[]=new Vector<String>[3];
But ... |
Given a byte array that is either a UTF-8 encoded string or arbitrary binary data, what approaches can be used in Java to determine which it is?
The array may be generated ... |
This is mainly a performance questions. I have a master list of all users existing in a String array AllUids. I also have a list of all end dated users existing ... |
I've been going through Sun Microsystem's Java Tutorial and got some questions while reading the following:
I/O from the Command Line: The Console Object
"Second, readPassword returns a character array, not ... |
I want to store a byte array wrapped in a String object. Here's the scenario
- The user enters a password.
- The bytes of that password are obtained using the getBytes() String method.
- They ...
|
I have a small problem here.I need to convert a string read from console into each character of string. For example string: "aabbab" I want to this string into array of ... |
I have a string that will be different each time but follow the form of
-3.33,-46.53,37.39,26.55,97.11,68.46,-32.46,-5.89,-62.89,-7.9,
and i want to remove each number and store as an double in an array.
even pseudocode ... |
I'm reading a file into an array and trying to take out the numbers and put them as a double in an array of their own. And apparently my middle name ... |
I am reading a char array from a file in and then converting it too a string using the String constructor.
read = fromSystem.read(b);
String s = new String(b);
This code has been ... |
I am making a site in JRuby on Rails, I am using some Java classes as well.
I have a select form element which passes user selections to the controller.
The selections are ... |
if I have,
String[] s = new String[3];
s[0] = "Ap";
s[1] = "p";
s[2] = "le";
String result = ?
If I want to get Apple out of s without looping, how do I do that?
Any ... |
I am writing a utility in Java that reads a stream which may contain both text and binary data. I want to avoid having I/O wait. To do that I create ... |
In the application there is a string in the following format:
String elements = "[11, john,][23, Adam,][88, Angie,]..." (... means there are more elements in the string)
From the given string I have ... |
Why is Object[].class.isAssignableFrom(String[].class) == true, while String[].getSuperClass() or getGenericInterfaces() could not get Object[]?
I checked the source of JDK, but i don't think i can get the answer myself.
For now, I know ... |
String product = Integer.toString(w);
char[] original = String.toCharArray(product);
This is the code I have so far. The error says that I can't use toCharArray on String, but I looked in the documentation, and ... |
The Java Docs for the method
String[] java.io.File.list(FilenameFilter filter)
includes this in the returns description:
The array will be empty if the directory is empty or if no names were ... |
I'm reading a file using bufferedreader, so lets say i have
line = br.readLine();
I want to check if this line contains one of many possible strings (which i have in an array). ... |
have small problem, and would very much appreciate help :)
I should convert byte array to string and get this output string: “[0, 0, 0, 0]”
After that another method should take ... |
I have a pattern @@{} and given a string I need to find out all the strings coming in between the curly braces.
Example :
If my string is Hi This is ... |
I am currently creating a java application in which I have a 2d array which I want to get some data into.
I am creating the 2d array as such
String[][] addressData;
and ... |
public class MatrixMultiply{
public static void main(String[] args) {
main();
}
static void main() {
...
|
would it be possible for an answer is psudocode please guys?
how could i write a method that, in O(n log n), takes a string array and removes null entries
i appreciate you ... |
What I want to do is ask the user for a number of strings to read into an array, and then ask the user to input that number of strings and ... |
In Java, how do I convert an array of strings to a array of unique values?
If I have this array of Strings:
String[] test = {"1","1","1","2"}
And I want to end up with:
String[] ...
|
Hi
I had a requirement of encoding a 3 character string(always alphabets) into a 2 byte[] array of 2 integers.
This was to be done to save space and performance reasons.
Now the ... |
I have a string which represents a multidimensional array in the format: [[A, a], [B, b]]
Is there a easy way to convert this string into multidimensional arrays.
Though, for now ... |
is there any function in java that converts string to byte array ?
|
I have a string variable
static String[] genrename;
I am assigning values to it in one of my method and then displaying its content.
It does store the value fine. But when I am ... |
Why do we have length of an array as an attribute. array.length and for String we have a method str.length()?
Just came in my mind, is there some reason?
|
See Related .NET question
I'm looking for a quick and easy way to do exactly the opposite of split
Someith that will cause ["a","b","c"] to become "a,b,c"
Iterating through an array ... |
i have written following code but it is throwing array index out of range exception
String options = "" + args[0];
if (options.toLowerCase().contains("failover"))
...
|
I am tring to convert a set of strings to a byte[] array. At first, I do something like this to convert a byte array to a string:
public String convertByte(byte[] msg) ...
|
public static String[] removeString (String[] original) {
String[] newString;
List<String> list = new ArrayList<String>(Arrays.asList(original));
list.remove(0);
newString = list.toArray(original);
return newString;
}
I'm ... |
I'm trying to go through an array of strings and print one index at a time, but when I tried running the program all I get is a 0 or 1. ... |
I created two array variables: s1 and s2
s1 contains {ram,raju,seetha}
s2 contains {ram}
I want to subtract the two arrays as sets, in order to get the following result:
raju
seetha
How can I ... |
We don't have the cp1251 code page available on a phone, so new String( data, "cp1251" ) doesn't work.
We need a function with signature something like
String ArrayCp1251toUTF8String(byte data[]);
|
I know this is a very simple thing, but I can't see any examples of doing this with strings. This is beyond the basic exercise in my self imposed homework, ... |
My code looks like this :
Vector<String> My_Vector=new Vector<String>();
String My_Array[]=new String[100];
for (int i=0;i<100;i++) My_Array[i]="Item_"+i;
......
My_Vector.addAll(My_Array);
But I got an error message, what's the right way to do it, without looping to add each item ... |
I know how to do toString method for one dimensional arrays of strings, but how to print two dimensional array ? With 1D I do it this way :
public String toString() ...
|
I have the below String assignment statement
String items[] = line.split("\",\"",15);
String fileNamet = items[1].replaceAll("\"","").trim();
I need to introduce a new if statement
if (valid) {
String items[] = line.split("\",\"",15);
} else ...
|
Okay, I know how to do it in C#.
It is simple as
Convert.ToBase64String(byte[])
and Convert.FromBase64String(string) to get byte[] back.
How can I do this in Java?
|
i'm using enums to replace String constants in my java app (jre 1.5).
is there a performance hit when i treat the enum as a static array of names, in a method ... |
I'm stuck with this pretty silly thing;
I got a textfile like this;
Hello::140.0::Bye
I split it into a string array using;
LS = line.split("::");
Then I try to convert the array values containing ... |
Hi is there a standard place for accessing empty array constants in the JDK > 1.5.
When I want to do a conversion from a String Collection (e.g. ArrayList)to a String Array ... |
Suppose I have this code:
String encoding = "UTF-16";
String text = "[Hello StackOverflow]";
byte[] message= text.getBytes(encoding);
If I display the byte array in message, the result is:
0000 FE FF 00 ...
|
I made the following "simulation":
byte[] b = new byte[256];
for (int i = 0; i < 256; i ++) {
b[i] = (byte) (i - 128);
}
byte[] transformed = new ...
|
Just a blackout, I want the String "hello hallo tjena hej tere" to an array broken at space.
|
I'm trying to make a class where I put a key and value into the put method which puts the key in the k string array and value into the v ... |
Is there a simpler way of implement this? Or a implemented method in JDK or other lib?
/**
* Convert a byte array to 2-byte-size hexadecimal String.
*/
public static String to2DigitsHex(byte[] bytes) ...
|
Is there a way to pass an array of String to a resource bundle to localize an unknown number of argument for a given key?
I have:
my.message=List of retired products: {0}
getValue(bundle, "my.message", ...
|
OK so for background I've only been using Java for a little more than a week and I am making a basic GUI "Recipe Book" application just to test out some ... |
Basically I have a proof-of-concept application that is a digital recipe book. Each Recipe is an object and each object has, among other fields, a Vector containing arrays. The ... |
I need to read a line like this from a file:
5 Chair 12.49
EDIT: I want to be able to have more lines of data.
I need to separate each word/number into different ... |
In a program I am writing I am doing a lot of string manipulation. I am trying to increase performance and am wondering if using char arrays would show a ... |
I like to convert string for example :
String data = "1|apple,2|ball,3|cat";
into a two dimensional array like this
{{1,apple},{2,ball},{3,cat}}
I have tried using the split("") method but still no solution :(
Thanks..
Kai
|
How do I search a string array with start with keyword?
for example,
String[] str = { "abcd", "abdc", "bcda"};
when my search string is "a" it must show
abcd and abdc
when my search string ... |
Say I have the following:
Class myclass
{
public string stra ="", strb = ""
myclass(String a, String b){stra=a;strb=b}
}
//then in the app I want to do:
myclass ...
|
I have a Java code defined as:
String[] where;
/**/where.append(ContactsContract.Contacts.HAS_PHONE_NUMBER+"=1");
/**/where.append(ContactsContract.Contacts.IN_VISIBLE_GROUP+"=1");
Those two appends are not working in this form, how would that work correctly?
|
import java.util.Scanner;
import java.lang.String;
public class SA3
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
...
|
I have text file as
0B85 61
0B86 6161
0B86 ...
|
I want to put some compressed data into a remote repository.
To put data on this repository I can only use a method that take the name of the resource and its ... |
I have a TextArea with enter seperated values:
For Example:
Value1
Value2
Value3
Value4
Value5
Is there a fast way to put them in a String array
String[] newStringArray = ???
|
I want to get a proxy list and parse it into an array of strings, txt is the proxy list, tmp[] is an array that has element in the form "ipaddr:port". ... |
Hi i want to read a txt file with N lines and the result put it in an Array of strings.
|
I'm trying to declare an enum type based on data that I'm retrieving from a database. I have a method that returns a string array of all the rows in the ... |
Intention is to take a current line (String that contains commas), replace white space with "" (Trim space) and finally store split String elements into the array.
Why does not this work?
String[] ...
|
Hoookay, so. I'm trying to get the longestS method to take the user-inputted array of strings, then return the element number of the longest string in that array. I ... |
I am on Ubuntu x64 bit running:
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (6b18-1.8-0ubuntu1)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)
and
jruby 1.4.0 (ruby 1.8.7 patchlevel 174) (2010-02-11 6586) (OpenJDK 64-Bit Server ...
|
I have an object array, I know that the elements are type String, say I need to access them many times.
- Practice 1: access the element by array index and cast it ...
|
i am wanting to check the total contents of a StringBuilder to see if it contains the same characters as a new string created randomly from a for loop using an ... |
let's say I have a string
String test = "This is a test string and I have some stopwords in here";
and I want to see how many times the words in the ... |
Is there a way to convert a byte array to string other than using new String(bytearray)? The exact problem is I transmit a json-formatted string over the network through UDP ... |
I know this sounds like a broad question but I can narrow it down with an example. I am VERY new at Java. For one of my "learning" projects, I wanted ... |
I have placed string argument in the method header called methodASet. Is it possible to use this string argument in the body and returns the words in the argument as a ... |
OK so here is some logic thinking... What I am trying to do is loop through strings until I hit a null/empty string.. then STOP. All while putting those strings inside ... |
Right now I have the following code:
String[] values = {str1, str2};
Utils.myMethod(values);
I would like to know if there is a way to do this all in one line. I've tried:
Utils.myMethod({str1, str2});
But that ... |
Is it a good idea to store words of a dictionary with 100.000 words in a static array of string. I'm working on spellchecker and I thought that way would be ... |
I'm looking to write an efficient n-order Markov chain method to generate random text strings given a set of example text. I currently have a Java implementation that uses several ... |
I have a method wherein i have to return a 2D String array.
The part of code for that method is as follow:-
public String[][] retrieveData(){
try{
int noOfRows = 0;
...
|
I have this array of strings
private static String[] colorsArray = { "#bde876", "#ff8581", "#ffc472",
"#faed75", "#a8c9e5", "#999999", "#e3a8e5", "#dddddd", "#fc603c",
"#ffcc00", "#74e8d4", "#3cd6fc" };
Then I ... |
i have a string="name";
i want to convert in an string array.\
how to do it?
is there any java built in function? manually i can do it but i'm searching for a java ... |
Is there any function in java like toString() to print a String array?
This is a silly question but I want to know if there is any other way than writing a ... |
What does scoring an array of strings means?
Does it mean checking for repeat count of every element?
|