如您所知,二进制文字是Java 7中引入的新功能:
int x = 0b1011;
System.out.println(x); // prints 11 as expected
Run Code Online (Sandbox Code Playgroud)
但是,当我试图从文字二进制文件中获取最大数量时,我得到了-1!
int x = 0b11111111111111111111111111111111;
System.out.println(x); // prints -1 !!!
Run Code Online (Sandbox Code Playgroud)
更多详情:
System.out.println(Integer.MAX_VALUE);
System.out.println(0b1111111111111111111111111111111); // 31 bits
/* Both print 2147483647 */
/************************************************************************************/
System.out.println(Integer.MIN_VALUE);
System.out.println(0b10000000000000000000000000000000); // 32 bits (increment by 1)
/* Both print -2147483648 */
/************************************************************************************/
// And if you keep increasing the binary literal, its actual value
// will be decreased until you reach the maximum binary literal and
// its actual value will be …Run Code Online (Sandbox Code Playgroud) 如何更改JFrame图标的大小?
JFrame f = new JFrame("Test");
Image icon = Toolkit.getDefaultToolkit().getImage("icons/logo.png");
// icon.setPreferredWidth()...
f.setIconImage(icon);
Run Code Online (Sandbox Code Playgroud) 如何将BigDecimal对象转换为使用指数形式的String表示?类似的东西:3.134e67?我查看了API并找到了,toEngineeringString()但它没有给我我想要的东西.
我试图通过使用HTML标签让JLabel显示新的行字符.但我想要的文字是从一种方法中获得的.这是代码行:
myLabel.setText("<html><pre>myCart.toString()</pre></html>");
Run Code Online (Sandbox Code Playgroud)
但是,这确实将标签的文本设置为myCart.toString(),而不是方法返回的String.有没有解决的办法?
我想让我jProgressBar在期间更新它的价值HTTP File Upload.我是Java新手,我不确定我做的是正确的事情,这是我的代码:
private static final String Boundary = "--7d021a37605f0";
public void upload(URL url, File f) throws Exception
{
HttpURLConnection theUrlConnection = (HttpURLConnection) url.openConnection();
theUrlConnection.setDoOutput(true);
theUrlConnection.setDoInput(true);
theUrlConnection.setUseCaches(false);
theUrlConnection.setChunkedStreamingMode(1024);
theUrlConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary="
+ Boundary);
DataOutputStream httpOut = new DataOutputStream(theUrlConnection.getOutputStream());
String str = "--" + Boundary + "\r\n"
+ "Content-Disposition: form-data;name=\"file1\"; filename=\"" + f.getName() + "\"\r\n"
+ "Content-Type: image/png\r\n"
+ "\r\n";
httpOut.write(str.getBytes());
FileInputStream uploadFileReader = new FileInputStream(f);
int numBytesToRead = 1024;
int availableBytesToRead;
jProgressBar1.setMaximum(uploadFileReader.available());
while ((availableBytesToRead = uploadFileReader.available()) …Run Code Online (Sandbox Code Playgroud) 我有一个字符串,其中包含由空格分隔的2个整数,后跟任何包含空格的字符串.
例:
23 14 this is a random string
Run Code Online (Sandbox Code Playgroud)
我该如何提取this is a random string?
整数不保证是两位数,因此我无法弄清楚如何使用indexOf和substring来提取这些数据.
提前致谢.
有时我看到类似的东西:
public class MainActivity extends Activity
{
public static final String url_google = "http://www.google.com";
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
Run Code Online (Sandbox Code Playgroud)
我实际上没有得到的,是为什么使用public static final,而不是 public final或final
我想向ArrayList添加特定元素.我可以这样做:
List<Employee> list = new ArrayList<Employee>();
List<String> list = new ArrayList<String>();
Run Code Online (Sandbox Code Playgroud)
但是,我想创建一个新的List,它包含Employee或String对象,而不是其他:
// This is
List<String or Employee> list = new ArrayList<String or Employee>();
Run Code Online (Sandbox Code Playgroud)
这可能吗?如果是,请解释我.
当我尝试做的时候,我已经搜索了高低,没有找到答案
import javax.imageio.ImageIO;
它说"无法解析符号图像".这是一个几乎完整的Android应用程序.我究竟做错了什么?
我正在使用下面的程序来分割我的字符串.
public static void main(String[] args) {
String test = "A1=CA2=BOA2=RA4=O";
String data[] = test.split("[A-a]\\d{1,100}=");
for (String str : data) {
System.out.println("Split data:"+str);
}
}
//Output
Split data:
Split data:C
Split data:BO
Split data:R
Split data:O
//But I want output something like below :
Split data:A1=C
Split data:A2=BO
Split data:A2=R
Split data:A4=O
Run Code Online (Sandbox Code Playgroud)
如何拆分字符串以上述方式获取输出
java ×10
swing ×4
android ×2
bigdecimal ×1
exponential ×1
extract ×1
file-upload ×1
html ×1
icons ×1
import ×1
java-7 ×1
java-io ×1
jlabel ×1
jprogressbar ×1
regex ×1
resize ×1
size ×1
string ×1
substring ×1
whitespace ×1