What is a buffer on java? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a homework to do on Java and is asks me to create a buffer method and the constructor should make an empty buffer structure.
There is no details about what that buffer is. It also wants to insert chars inside the buffer, delete the char that buffer shows, go buffer X positions left or right and tell the number of buffers chars. All these with different methods.
The problem is WHAT IS THAT BUFFER??? Is this something specific?

I would just use a StringBuilder. There are many other possible solutions but StringBuilder is the most widely used buffer for chars these days.
StringBuilder sb = new StringBuidler();
It also wants to insert chars inside the buffer,
sb.append('!');
sb.append("Hello");
sb.insert(5, "bye");
delete the char that buffer shows,
sb.delete(3, 6);
go buffer X positions left or right and tell the number of buffers chars.
sb.charAt(5); // character at 5
int len = sb.length(); // number of characters.

Related

How to know file size from bytes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have byte array, how to know file size ? (in JAVA)
File file = new File("patch");
file.length() // <--- it's good, but I haven't original file... (( I get file in bytes from DataBase !
Thanks
You have an array with you and every array has a length. That's it.
byteArray.length;
And
1kb = 1024 bytes

How to display a portion of a string at an index of a string array [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a string array
String[] albumnames;
now how to take a string from particular index position with limited number of charachters.
For example,
if, albumnames[position] have value "abcdefghijk"
then i want to take the first 5 characters only.
That is "abcde".
The substring method of String can be used to achieve this. Try
String s = albumnames[position].substring(0,5);
See substring docs
albumnames[position].substring(0,5);
you can see the methods in String class, like substring, indexof

2D Array and a loop within an interval [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to crate a loop which sums the arrays values which are within the interval (for instance 2-5). My main problem is getting from the first checked value of the array to the next one and so on. Thankyou in advance.
int x=0,y=0,s=0;
int[][] myArray = { {0,1,2,3}, {3,2,1,0}, {3,5,6,1}, {3,8,3,4} };
Scanner scan = new Scanner(System.in);
int b = scan.nextInt();//lowest value
int c = scan.nextInt(); //highest value
if (myArray[x][y]>b || myArray[x][y]<c)
s=s+myArray[x][y]
//then check next one
if (myArray[x][y]>b || myArray[x][y]<c)
s=s+myArray[x][y]
You need to put these in a nested for-loop. Otherwise, they are executed only once, with x=0 and y=0. So all you are doing is essentially:
if (myArray[0][0]>b || myArray[0][0]<c)
s=s+myArray[0][0]
So s could only possibly be 0 or the first element in the 2D array.
Now, this conditional:
if (myArray[x][y]>b || myArray[x][y]<c)
does not mean what you think it means. This would evaluate to true for all numbers as long as b is less than c. For the semantics you are looking for, you want an AND operator (&&).

How do I split a String in Java up to a certain point, keeping everything after that point as a separate string? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What I am looking to do is split a given string in Java using a tab delimiter. After the seventh split, I would like to keep everything after that point as an eighth split. This last split will contain tabs also, but must remain intact.
Use the split method that takes two parameters, the second being the split limit. You can pass in a limit of 8. The eighth element will contain the rest of the string after the seventh split.

How to create random cell number for testing purpose [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have to create a random cellnumber 07939393914 for automation testing purpose.
Last 079393(5 digits) digits should change randamly.. each time test runs..
Can any one suggest JAVA code for this ? or else Selenium Java code ?
Thanks
Is this a number or a String? I ask as it has a leading zero.
Take you initial number as 7939300000
then add to it Math.round(Math.Random()*10000)
If you want it as a String, take your string as "079393" and use Integer.toString on the result above, then concatentate them
Use RandomStringUtils class.
String randomNumbers = RandomStringUtils.randomNumeric(5);
String phNo = 079393+randomNumbers;
var num=Math.ceil(Math.Random()*100000)
for random first 5 digit numbers
and add
var your_last_5digits; //as string to your last 5 digits
cellNumber='0'+num+your_last_5digits;

Categories